Custom Post Templates

I think this approach will work. 1.create template for single post like singlepost.php( default single post template),singlepost-99.php,singlepost-101.php. 2.now put just this code in single.php <?php global $post; get_template_part(‘singlepost’,$post->ID); ?> what this code does check for single post template for current post by post id if not found call singlepost.php. Important Link: get_template_part()

How To Add One Tag to Multiple Posts?

If you have the ability to use wp-cli on a bash-like shell it’s a handy way to do this: for ID in $(wp post list –post_type=post –post_status=any –field=ID); do wp post term add $ID post_tag old; done for ID in $(…); do starts a loop for each line of output of the internal command wp … Read more

how to replace embedded “full” sized images within a post with the “large” ones

I solved my own problem by using the creating a page using the following template. Just create and visit the page using the template below. You will only be viewing the results with primitive pagination, follow the code and it’s easy. Changes will not be saved until you visit /whatever-permalink-you-have/?updating=true Caution Please backup your database … Read more

Only display a certain number of posts, dependent on how many posts there are available in a query

You don’t have to run two queries, as you already got what you want (even more). $args = array ( ‘post_type’ => ‘mytheme_posttype’, ‘post_status’ => ‘publish’, ‘numberposts’ => 12, ); $sliderQuery = new WP_Query($args); $num_posts = $sliderQuery->post_count; if ($num_posts >=4) { if ($num_posts >= 12) $postsToPrint = 12; elseif ($num_posts >=8) $postsToPrint = 8; else … Read more

Add scripts on custom post add/edit pages Not Working

There are a few things you’ll want to do to make you include work and in generally better. Here is the complete code: function my_theme_enqueue_admin_scripts() { $screen = get_current_screen(); // This is how we will check what page we are on if ( in_array( $screen->id, array( ‘post’, ‘page’) ) && $screen->action == ‘add’ ) { … Read more

When trashing a post, also trash related comments

Well, this is partly true and partly false. When you trash a post, everything that is tied to it is also trashed. This means, if you untrash the post, the comments etc. are untrashed as well. However, comments and other stuff is not handled as if they were trashed directly (i.e., on the Comments page … Read more

Check is_single() outside loop

In your example, you can’t. Per the Codex, [is_single()] checks if a single post of any post type except attachment and page post types is being displayed. You’re trying to use it on the transition_post_status hook, which is not related to page display, and so is_single() has no meaning. The Solution Instead of using is_single(), … Read more

Reset/Reorder posts ID in the MySQL wp_posts table

If you want sequential numbers for your posts, then don’t use the post ID column. AUTO_INCREMENT is meant to provide unique numbers (and split-brains in multi-master replication), it is never going to be without gaps, especially not in WordPress (revisions, autosaves, pages, contact forms, galleries and a bunch of other plugins) and especially not with … Read more

How to disable single post view in wp

You can add to the end of theme’s header.php file this: if( is_single() ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( ‘404’ ); exit(); } Note that the get_template_part( ‘404’ ) function needs 404.php file in your theme directory.