Counting number of posts with Category B in Category A

Make use of the WP_Query class, namely the tax_query and fields parameters. Get the count from the $found_posts property. Please note, this is exemplary code. $query = new WP_Query( [ ‘post_type’ => ‘games’, ‘tax_query’ = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘game_status’, ‘field’ => ‘slug’, ‘terms’ => [ ‘beaten’ ], ], [ ‘taxonomy’ => … Read more

Duplicate Queries

Generally speaking, you could use the WP Transients API to save the query. // Get any existing copy of our transient data if ( false === ( $special_query_results = get_transient( ‘special_query_results’ ) ) ) { // It wasn’t there, so regenerate the data and save the transient $special_query_results = new WP_Query( ‘cat=5&order=random&tag=tech&post_meta_key=thumbnail’ ); set_transient( ‘special_query_results’, … Read more

Multiple orderby parameters in pre_get_posts() action

Never forget that there’re actually two filters // Add additional query args that are allowed by the API by default pre_get_posts // Modify the query herself posts_clauses // Inspect the resulting string – test this one in for e.g. phpMyAdmin posts_request So everything you can achieve using the pre_get_posts filter should be done there. The … Read more

How do I get a meta value from WP_Query?

I’ve found a solution to my problem myself. Since none of the already existing answers solved the problem, I figured I could best post mine here to help people with similar problems. The solution: if($res->have_posts()) { $id = $mail_res->posts[0]->ID; // blindly assuming there is only 1 post having baz = baz_value $true_baz = get_post_meta($id, ‘baz’)[0]; … Read more

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