Displaying custom post type listing

Instead of using the ‘single_template’ filter use the more generic ‘template_include’ filter for both archive annd single post view: add_filter(‘template_include’, ‘my_custom_templates’); function my_custom_templates( $template ) { if ( is_single() && ( ‘book_reviews’ == get_post_type() ) ) { if ( ! locate_template(‘single-book_reviews.php’, false) ) $template = plugin_dir_path( __FILE__ ) . ‘/single-book_reviews.php’; } elseif( is_post_type_archive(‘book_reviews’) ) { … Read more

CPT to installable Plugin

There are other factors that you’ll discover along the way, but basically it boils down to: move all that’s CPT related from your theme’s functions.php to a plugin file. Create a PHP file, put the plugin’s header information, add to the plugins folder, activate. Now, you separated appearance (theme) from functionality (plugin). Here are two … Read more

Highlight current post type when inside custom post type

I am assuming that your code is on a “single” post/cpt page. echo ‘<ul>’; $loop = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 4, ‘order’=>’ASC’ ) ); $obj = get_queried_object(); $thispage = $obj->ID; while ( $loop->have_posts() ) : $loop->the_post(); ?> <li><?php if ($thispage === $post->ID) { $class=” class=”current-item””; } else { $class=””; } the_title( … Read more

Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT

Note that category and post_tag are both taxonomies, and that they are taxonomies that, by default, are only supported by the post post type. You have created a custom post type, and have registered support for a custom taxonomy for it: books_taxonomy. Thus, it makes perfect sense that a query for posts with the books … Read more

Passing variables through permalink structure in custom post types

The one issue I see immediately with your rewrite rule is this part: index.php?pagename=charities You don’t have a page named “charities”, you have a custom post type, so that should be: index.php?charities=$matches[1] assuming your custom post type query var is charities. HOWEVER, that said, I would not add rewrite rules for this, WordPress will take … Read more

Associate Posts with individual user – hide from other members

The basis for making this work is actually pretty simple. Essentially, you just need to hook pre_get_posts and set the author query var to the value of the currently logged in user for each type of query you want to limit results on. function logged_in_user_posts( $query ){ if ( is_user_logged_in() ){ global $current_user; get_currentuserinfo(); $query->set( … Read more