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 | Help me create a search term with an ‘OR’ relation?

(Revised on March 25 2020 UTC) So in this revised answer, I’ll just begin with the code: Define the variables: (I intentionally included only the $args part) // define POSTed/submitted variables here like $paged, $display_count and $direction // define the offset/’direction’ stuff here // then define your $args array $args = array( ‘post_type’ => ‘product’, … 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

if wp_query taxonomy term have posts

I’m not sure what you exactly need, but normally, by default, get_terms returns only terms that actually have posts assigned to them $terms = get_terms( ‘exhibition’ ); var_dump( $terms ); Apart from this, I really do not know what you exactly need

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