How can draft post after 1 year

Try this code (maybe working) , but i’am not sure cause not testing : function amin_show_expire(){ global $wpdb; $result = $wpdb->get_results(“SELECT * FROM wp_posts WHERE post_type=”CUSTOM” AND post_status=”publish””); if( !empty($result)) foreach ($result as $a){ $show_time = get_the_time(“Y-m-d”, $a->ID ); $show_time=date(“Y-m-d”, strtotime(“+1 years”, strtotime($show_time))); if ( $show_time < date(“Y-m-d”)){//compare 1 year after post with current time … Read more

Edit Posts Page but not category specific pages?

You can create a Page template in which display all posts with your custom markup. <?php /** * Template Name: My Custom Blog * */ // The Query $args = array(‘posts_per_page’=>-1); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ … Read more

Query post for today, if no post get the previous one

I think you should make a recursion function that will call itself if there’s no posts found passing new date to query for.. function getDatePosts( $date, $query_args ) { $query_args[‘date_query’] = array( ‘year’ => date( ‘Y’, $date ), ‘mounth’ => date( ‘m’, $date ), ‘day’ => date( ‘d’, $date ) ); $query = new WP_Query( … Read more

update post category in a new table on frequent change of category

You could use an Action Hook ‘save_post‘ to implement the requirement and this way categories will stay synced with your custom table and default tables. Example : function post_updated_sync_category( $post_id ) { //Here you get postid of the post being updated //You can put your code to update in custom table here } add_action( ‘save_post’, … Read more

Show short text of content

One potential issue I see with that is if the content contains Shortcodes. You can strip Shortcodes before passing it to wp_trim_words if you want them removed, or alternately, if you want to maintain them you can apply the Shortcodes beforehand. You may also want to check that $news_item[“post_excerpt”] is not empty, in case a … Read more

Add new post using a page inside the website

You have never read the WP documentation? Create any template and form and when submitting the form it could be Example: $args = array(‘post_type’=>’post’, ‘post_title’=>’your title’, ‘post_status’=>’publish’, ‘post_content’=>’post content’); wp_insert_post ($args); This will allow any post page or custom post type to insert the post