Fetch post meta in the same query as the main loop

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

pre_get_posts not firing at all

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.

pre_get_posts main_query not displaying after applying tax_query filters

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

Help with SQL query, how to add taxonomie terms with value stored in options?

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

Order posts by custom column using pre_get_posts

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)