wp_query display posts from same category of the post

I’ve found an answer: <?php $cats = get_the_category(); $args = array( ‘post_type’ => ‘article’, ‘post__not_in’ => array( get_the_ID() ), ‘posts_per_page’ => 5, ‘cat’ => $cats[0]->term_id, ‘meta_query’ => array( array( ‘key’ => ‘recommended_article’, ‘value’ => ‘1’, ‘compare’ => ‘==’ ) ) ); $query = new WP_Query( $args ); ?> <?php if( $query->have_posts() ) : while( $query->have_posts() … Read more

wp_transients | wp_object_cache VS SESSIONS & Cookies?

set_transient() using wp_cache_set() and mysql database. WP Cache API using $GLOBAL(global session for application). Cookies and Session saves data only for one current user(cookies in browser, sessions on backend). I think better using set_transient(), it has nice hooks and save all data global, even on site disabled cache.

How is WP_Query connected to WP_Post in The Loop?

Yes, an object containing other objects is “natural”. A House object contains an array of Furniture objects in its $furnitures property… Such as in our case… WP_Query contains an array of WP_Post objects in its $posts property… A one-to-many relationship. This is an Aggregation. OOP is all about programatically modelizing things. These things are: From … Read more

Why use JSON API to display recent posts?

The JSON API is just a wrapper for WP_Query bundled with RESTful endpoints (add_rewrite_rules). Its a way to speed up production by providing a framework which you otherwise would have to code yourself. In fact, if you build custom endpoints, you’ll end up using your own QP_Query loops! The choice is really going to come … Read more

How to wp_query posts with ajax

I would like to make a series of comments, but the overall length would be too long for a comment, so I have to write an answer. You should state what is working and what is failing, and tell us what you have tried to get it working. Looking at your code is too general. … Read more

Get posts using WP_Query

It’s quite some time since I worked with WordPress, but it seems to me that: You’re executing the query twice. First when you pass $args to the constructor during instantiation. Second when you call query(). With this, you’re essentially overwriting the first query (the one that contains the orderby=rand). The documentation of WP_Query mentions that … Read more

$wp_query->current_post restarts from zero on paged pages

$wp_query->current_post holds information about current post in loop, not global set of posts. Numering posts across multiple pages is not available natively (as far as I know) and probably would be to unreliable (for example what if number of posts per page changes is customized to be uneven?). For specific implementation building custom numbering, based … Read more

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