Skip to content

Instantly share code, notes, and snippets.

@eri-trabiccolo
Last active August 29, 2015 14:16
Show Gist options
  • Save eri-trabiccolo/14ade3c986e9f3086843 to your computer and use it in GitHub Desktop.
Save eri-trabiccolo/14ade3c986e9f3086843 to your computer and use it in GitHub Desktop.
Customizr > 3.3.11 <? custom post lists
<?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') );
}
}
@giorgioriccardi
Copy link

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

@eri-trabiccolo
Copy link
Author

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