First x post with another template then the others

It shows more than 3 posts because you used post_per_page when it should be posts_per_page (note the plural “posts”). But actually, you can use the same query and use a counter to display the different template parts: $loop = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ) ); $c = 1; // post … Read more

wpdb COALESCE won’t work

From what I could see, the query did return a result, but the COALESCE() result was not named, hence MySQL and WordPress use the entire COALESCE() query as the field name. To avoid that, you would use an alias for the COALESCE(), e.g. //$query = “SELECT COALESCE( <your queries> ) AS <alias>”; $query = “SELECT … Read more

How to ignore posts in pre_get_posts?

What about this one? function opby_query( $query ) { if ( $query->is_main_query() ) { if ( $query->is_home() ) { $query->set(‘posts_per_page’, 15); }; if ( isset( $query->query_vars[‘ctrl_podcasts_status’] ) ) { // get main query args $subquery_args = $query->query_vars; // add tax_query filter $subquery_args[‘tax_query’] = array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘podcast-control-daily’ … Read more

Why my query ‘REPLACE INTO…’ does not work?

The reason is due to this code inside dbDelta() : // Create a tablename index for an array ($cqueries) of queries. foreach ( $queries as $qry ) { if ( preg_match( ‘|CREATE TABLE ([^ ]*)|’, $qry, $matches ) ) { $cqueries[ trim( $matches[1], ‘`’ ) ] = $qry; $for_update[ $matches[1] ] = ‘Created table ‘ … Read more

How to query 2 custom post types that need to share a slug?

Note that a filter callback must always return something which is commonly the first parameter passed to the callback. So for example your overwriteQueryVars() function, it must always return the $query because request is a filter hook. Secondly, instead of overwriting the entire query arguments (e.g. by doing $query = array( … ) or $query->query_vars … Read more

unable to use ‘new WP_Query’ in AJAX call

Just to clear this up for someone that might have similar problem, everything was find with query, the problem with this was WordPress was looking for WP_Query class in namespace file, replacing new WP_Query with new \WP_query solved this problem 😀 thanks for help!

Query multiple taxonomies with pre get posts

I can’t seem to find a way to set the query more than one taxonomy You already found it, but the problem is, you should have not done this: $tax_query_array = array(‘relation’ => ‘OR’); $speciality_select ? array_push($tax_query_array, …) : null ; $query->set( ‘tax_query’, $tax_query_array); $tax_query_array = array(‘relation’ => ‘OR’); $industry_select ? array_push($tax_query_array, …) : null … Read more