Last active
August 29, 2015 14:16
-
-
Save eri-trabiccolo/14ade3c986e9f3086843 to your computer and use it in GitHub Desktop.
Customizr > 3.3.11 <? custom post lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /*Add the following code at the very beginning of your template file, just after the Template declarative block */ ?> | |
<?php | |
// strangely you have to set this to false, typo in the core code. | |
// useful just when you display the page which uses this template in home as static page | |
// consider that the navigation will not work properly (and not because of customizr :P) | |
add_filter('tc_display_customizr_headings', '__return_false'); | |
add_filter('tc_post_list_controller', '__return_true'); | |
// use this to display the page title | |
add_action('__before_loop', 'print_page_title', 0); | |
function print_page_title(){ | |
?> | |
<header class="entry-header"> | |
<h1 class="entry-title "><?php echo get_the_title(); ?></h1> | |
<hr class="featurette-divider __before_content"> | |
</header> | |
<?php | |
} | |
?> | |
<?php /*Append the following code to your child-theme functions.php just if you want to display the page using the template as static page in home */ | |
/* as you can see here I've not used the php starting and closing tags since | |
your functions.php already starts with the first and doesn't have to be closed with the second!*/ ?> | |
// move list headings action | |
add_action('after_setup_theme', 'move_list_headings_action'); | |
function move_list_headings_action(){ | |
if ( class_exists('TC_headings') && method_exists('TC_headings', 'tc_set_post_page_heading_hooks') ){ | |
remove_action( 'wp' , array( TC_headings::$instance , 'tc_set_post_page_heading_hooks') ); | |
add_action( 'wp_head' , array( TC_headings::$instance , 'tc_set_post_page_heading_hooks') ); | |
} | |
} |
Hi Rocco,
I'll move the question to the forum, maybe somebody else has already a solution for this
Hey Rocco, problem solved:
https://github.com/giorgioriccardi/filtering-cpt-and-ct-in-WP-customizr-theme/blob/master/publications-page.php#L64
I was missing the part 'tax_query'... so many new things in WP all the time:
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
this is a working custom loop that filters CPT, CT and related category:
<!-- custom loop 1 -->
<?php
add_filter('tc_show_post_metas', '__return_true'); //this applies only to Customizr theme
global $wp_query, $wp_the_query;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$wp_query = new WP_Query( array(
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'post_type' => 'publication',
'tax_query' => array( //https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
array(
'taxonomy' => 'publication-types',
'field' => 'slug',
'terms' => 'reports',
)
),
'post_status' => 'publish',
'posts_per_page' => 2, //show n posts
//'cat' => 77, //include this category from the posts list
//others parameters here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
) );
?>
Ciao
Hello Giorgio,
sorry for haven't replied, I don't get notified about new comments on gists.. do you know I could I? :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Rocco, I know this is not the place where to follow up / ask about custom loops (I will eventually post it on the forum when solved).
I have this problem, I don't seem to be able to filter a query for CPT with custom taxonomy; I have a CPT called 'publication' and a CT called 'publication-types'; under 'publication-types' I created some categories and one of those is called 'reports'.
I'm trying to filter in a custom loop 2 posts out of 'reports' only: http://www.firstcall.workingdesign.ca/publication-types/reports/ and in the future I will try to have 2 loops filtering also another category called 'letters', but for the sake of the question let's consider only 'reports'.
Here is the code I'm trying to put in my page template:
well, it does not work because I'm missing the point, it outputs only the 2 most recent posts under 'publication', what am I missing && || doing wrong?
https://github.com/giorgioriccardi/filtering-cpt-and-ct-in-WP-customizr-theme/blob/master/publications-page.php#L58