Custom Post Types (Changing post style based on category)
You’re missing the endwhile Maybe you didn’t copy/paste it in, but if it’s not in your file you’ll want to add it.
You’re missing the endwhile Maybe you didn’t copy/paste it in, but if it’s not in your file you’ll want to add it.
Question #1: I don’t really understand this question, but what you have done looks alright. I might add the pre_get_posts filter in the same place as register the post type– presumably a plugin file– but registering in the theme should work. It won’t transfer to another theme if you do that though. Question #2: You … Read more
In case anyone runs into trouble like I did, I figured it out! $taxonomy_1 = get_terms( ‘taxonomy_1’, $args_1 ); $taxonomy_2 = get_terms( ‘taxonomy_2’, $args_2 ); foreach( $taxonomy_1 as $tax_1 ) { foreach( $taxonomy_2 as $tax_2 ) { $posts = get_posts( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘ENTER-YOUR-CPT’, ‘order’ => ‘ASC’, ‘orderby’ => ‘title’, ‘taxonomy’ => … Read more
yes, that is a cool idea! this kind of already happens in the quick edit, if you think about it… you just have to find the code that generates the quick edit and put it on the side like in the layout you showed. another way to go about it, look into this tutorial, which … Read more
To show custom post type on a page, try something like this //place code to display the title here if ( get_post_type( $post->ID ) == ‘posttypename’ ){ //place code to display fields here } else { //place code to display excerpt here }
I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop. An exmaple: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args=array( ‘post_type’=>’post’, ‘cat’ => 6, ‘posts_per_page’ => 5, ‘paged’=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* … Read more
toscho’s answer is correct as to the technical reasons to define your CPT in a plugin, but it seems to me that much of you question stems from a misunderstanding of the template hierarchy. Almost, but not quite, every template file that you’ve seen is optional. With the exception of the basic index.php template file, … Read more
I can’t comment on your scripts, but if you change anything related to permalinks – it is always advisable to go to the Dashboard -> Settings -> Permalinks and click the “Update” button. This tells WordPress to flush its rewrite rules. If your script is correct, then after doing the “Update” – you won’t get … Read more
I … want to … switch the posts with a next & prev button in [a] sidebar. But only the permalink … changes. You do not say what the permalink is changing to. It sounds like you might be talking about pagination in a custom loop. Your query ignores the page number and always returns … Read more
Bulk remove category from custom post type?