Display post from specific date

I think if you want to show recent posts posted 2-3 days ago, you can use date queries, provided by WordPress You can get more information about date queries from here: WordPress Date Queries For Example: If you want to show last three days posts, it can be done using the following snippet of code: … Read more

If Specific Post, Link Elsewhere

The reason why your check didn’t work is because is_singular() checks for post types, not for post IDs. is_singular( ‘product’ ) checks if the current post is of the type product, nothing else. The comparison 2295 === get_the_ID() does exactly what you need.

Bulk update post slugs through database

Try this query, remembering to change out your_posts_table with the proper name in your database. Using CONCAT, you can add any number of strings, just pass post_name to add your changes before/after. update your_posts_table set post_name = CONCAT(‘pre-‘, post_name) More info on MySQL CONCAT Note: Use a WHERE clause if you only want to update … Read more

How to display different number of posts

This can be done with a very short plugin. function posts_on_home_page( $posts_per_page ) { if ( is_home() ) return 5; return $posts_per_page; } add_filter( ‘pre_option_posts_per_page’, ‘posts_on_home_page’ ); This is actually pretty close to the Codex example for pre_option_(option_name).

Publish a Post on a Future Date Automtically

From digging through /wp-includes/post.php, it looks like you may need to do the following: set your post_status to future set the post_date to when you want it published insert the post as your code shows Run the following code after inserting the post $time = strtotime( $postdate . ‘ GMT’ ); wp_schedule_single_event( $time, ‘publish_future_post’, array( … Read more

Understanding and using metaboxes in posts

To save: // Update and save the field so it can be used in our template if ( isset( $_POST[‘input_name’] ) ) { $data = sanitize_text_field( $_POST[‘input_name’] ); update_post_meta( $post_id, ‘field_name’, $data ); } To read: $data = get_post_meta( $post_id, ‘field_name’, true ); // With post object, a leaner, cleaner method: $data = $post->field_name; There’s … Read more

Random post category URL

Pro tip – don’t custom query unless you need to (you don’t). And never use the guid field. if ( is_singular() && $cats = get_the_category() ) $cat_id = $cats[0]->term_id; // Category ID for current post elseif ( is_category() ) $cat_id = get_queried_object_id(); // Category ID for current archive else $cat_id = 0; // No cats … Read more