Select posts wich has no relationship in custom taxonomy

I have found an answer by myself, for those landing here by google: $taxq = array( array( ‘taxonomy’ => ‘story_lng’, ‘field’ => ‘id’, ‘operator’ => ‘NOT EXISTS’, ) ); That results in AND (NOT EXISTS( SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = ‘story_lng’ AND wp_term_relationships.object_id = wp_posts.ID)) AND … Read more

What’s wrong with this WP query?

Turns out, WordPress joins the postmeta table several times, depending on the meta query arguments. Yes that’s correct, and it’s also the reason why I said (in my other answer) that in an orderby array, you should use the key of an array in the meta_query which contains a direct item named/keyed key (where the … Read more

pagenavi with merged wp_query [duplicate]

The WP_Pagenavi FAQ links to the following article to explain how to use the Pagenavi plugin with a secondary query by passing the wp_pagenavi() function a query parameter. From the tutorial: $my_query = new WP_Query(); while ( $my_query->have_posts() ) : $my_query->the_post(); the_title(); // more stuff here endwhile; wp_pagenavi( array( ‘query’ => $my_query ) ); wp_reset_postdata(); … Read more

How do I create my own nested meta_query using posts_where / posts_join?

Here is a rough outline of how you’d go about making a UNION work with WP_Query. add_filter( ‘posts_request’, function ($clauses) { $clauses = str_replace(‘SQL_CALC_FOUND_ROWS’,”,$clauses,$scfr); $scfr = (0 < $scfr) : ‘SQL_CALC_FOUND_ROWS’ : ”; $clause2 = $clauses; // manipulate this return “SELECT {$scfr} u.* FROM (({$clauses}) UNION ({$clause2})) as u”; }, 1, 2 ); Set up … Read more

Use Transient API to cache queries for all posts in all categories?

You’re saving every query object for each category to the same transient. Because this happens fast and time frame is one day, you’re always getting the query object for the first category back. Make your transient name variable with the category, e.g. like this: $query_category_posts = get_transient(‘cached_posts_’ . $category ); Of course you then need … Read more

WP_query and pagination?

If you could tell us what you’re exactly trying to achieve, we can help you better! <?php $paged = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1; $args = array( ‘post_type’ => ‘question’, ‘posts_per_page’ => -1, ‘paged’ => $paged, ‘author’ => $user_id ); $my_query = new WP_Query($args); if($my_query->have_posts()): while($my_query->have_posts()):$my_query->the_post(); //Loop goes here… endwhile; //support for page-navi plugin, please … Read more

Function to check if author has posted within the last x days

Yes, it is possible and it is pretty small change in your code… get_posts() uses WP_Query, so you can use all params from this list: https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters So here’s your code after changes: $args = array( ‘post_type’ => ‘your_custom_post_type’, ‘author’ => get_current_user_id(), ‘date_query’ => array( array( ‘after’ => ‘- X days’, // <- change X to … Read more

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