Re-order posts inside tax query
Re-order posts inside tax query
Re-order posts inside tax query
You can’t use double sorting option. You can try this code once: add_action( ‘pre_get_posts’, ‘fetch_staff_people’ ); function fetch_staff_people( $query ) { if ( is_post_type_archive(‘staff’) && $query->is_main_query() ) { $query->set( ‘post_per_page’, ‘-1’ ); $query->set( ‘meta_key’, ‘_staff_purpose’ ); $query->set(‘orderby’, ‘meta_value_num’); // sort by purpose, then by staff name. $query->set( ‘order’, ‘ASC’ ); } } Note: I used … Read more
Try adding this to your functions.php. function my_custom_get_posts( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search() ) { $query->set( ‘post_type’, array( ‘post’, ‘movie’ ) ); } } add_action( ‘pre_get_posts’, ‘my_custom_get_posts’, 1 ); Also make sure you do not have any other pre_get_posts action overwriting this function’s effect.
The issue I had with my search was that the select field’s name was the same name as the taxonomy being queried. When I used a different name for the select field my query worked as it should. <?php wp_dropdown_categories(array( ‘name’ => ‘special_day_select’, //anything else besides an existing taxonomy name. ‘taxonomy’ => ‘special_day’ )); ?> … Read more
In general this would make sense at pre_get_posts since you could just express conditions as meta query and let WP figure out SQL. In your specific case this won’t work, since that format is horrible for programmatic comparison. Unless you can change format to something more friendly, you will probably have to write some pretty … Read more
ok folks, i did it anothere way.. here’s how i did it: add_filter( ‘pre_get_posts’, function( $query ) { if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( ‘section’, false ) ) return $query; global $wpdb; $section = $query->get( ‘section’ ); unset( $query->query[‘section’] ); unset( $query->query_vars[‘section’] ); $query->tax_query = false; $query->set( ‘tax_query’, false ); $cateroties = … Read more
Include attachments with a custom taxonomy in search
I found out the answer myself. There are other filters that let you adjust the query before it’s run: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_clauses The posts_clauses filter runs before the query gets executed and is essentially the sum of all filters that run immediately before it. Apart from posts_clauses, there are several more precise filters that modify only a … Read more
wp_query – Modify $query to include duplicate content
You are so very close. In your first line just replace get_option with get_theme_mod and you’re done, provided you have already added a customizer control for posts_per_page_option in the usual way.