Error function query

You have to pass in the $query variable to use it in your function; if you don’t, PHP uses null. Try: function elc_cursos_en_el_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘post_type’, array( ‘post’, ‘CursoTL’ )); } } add_action( ‘pre_get_posts’, ‘elc_cursos_en_el_blog’ ); See pre_get_posts for the hook’s documentation.

How can I display custom post types on a page?

Easy: modify the query… (and add some comment on top to make a template out of this…) $query_default = new WP_Query( array( ‘orderby’ => ‘menu_order’ ,’order’ => ‘ASC’ ,’post_type’ => ‘custompost’ // THIS IS WHAT YOU’RE SEARCHING FOR ,’post_status’ => ‘publish’ ) ); if ( $query_default->have_posts() ) : while ( $query_default->have_posts() ) : $query_default->the_post(); endwhile; … Read more

Limiting posts_join, where, etc to a specific WP_Query object?

The most reliable way is to define your own query var and then check it: $my_query = new WP_Query( array( … ‘context’ => ‘my_query’ ) ); Then, from your callback: function alter_post_clauses( $clauses, $wp_query ) { if ( ‘my_query’ == $wp_query->get( ‘context’ ) ) { // do stuff } return $clauses; } add_filter( ‘posts_clauses’, ‘alter_post_clauses’, … Read more