What kind of object type is WP_Query?

I’m not sure you understand the logic of WP_Query. Rather than explain in words, here’s a code example; $query = new WP_Query( array( ‘meta_key’ => ‘Old ID’, ‘meta_value’ => $atts[‘oldid’] ) ); if ( $query->have_posts() ) return $query->posts[0]->post_title; return ”; Check out the codex on interacting with WP_Query. UPDATE: To use the query as you … Read more

Get posts by menu ID

I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the wp_get_nav_menu_items() function that helped me. I finnally came with this, 220 was my menu_id $navcat = wp_get_nav_menu_items(‘220’); foreach ($navcat as $obj) … Read more

How-to exclude terms from the main query the most performant way?

You can set the taxonomy query for the main query using pre_get_posts: add_action( ‘pre_get_posts’, ‘my_exclude_terms_from_query’ ); function my_exclude_terms_from_query( $query ) { if ( $query->is_main_query() /* && whatever else */ ) { $tax_query = array ( array( ‘taxonomy’ => ‘category’, ‘terms’ => array( ‘cat-slug’ ), ‘field’ => ‘slug’, ‘operator’ => ‘NOT IN’, ) ); $query->set( ‘tax_query’, … Read more

How to paginate attachments in a secondary query as gallery?

I’m assuming you want something like this: |———————| | content | | (static) | |———————| | gallery | | (paged) | |———————| | << pagelinks >> | |———————| In this setup your the post content stays the same, appears to be static, while the gallery is paged. This means you have the main query, showing … Read more

Displaying several specific pages using WP_Query()

If you look at the query object after those queries are run, you’ll see that none of those examples are doing what you think they’re doing. The first issue is that you can’t mix query string and array parameters, and the second issue is that pagename can only be used to load a single page. … Read more

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