wp_query conditionally get posts

You can check if a query has posts with if( $your_query->have_posts() ), and only output the container if it passes that test. $featuredPosts = new WP_Query( array( ‘posts_per_page’ => 2, ‘cat’ => 6, ‘offset’ => 4 ) ); if ( $featuredPosts->have_posts() ) : echo(‘<ul class=”right-hang”>’); while ( $featuredPosts->have_posts() ) : $featuredPosts->the_post(); endwhile; echo ‘</ul>’; endif;

Pagination With Custom WP Query not functioning

One issue at least: you’ll want to close the loop before outputting your pagination links, or else they’ll be output on every iteration of the loop. But you’ve got paginate_links() before endwhile;. Try this arrangement instead: // open loop if ( have_posts() ) : while ( have_posts() ) : the_post(); // Loop markup // close … Read more

Including ‘cat’ => $cat breaks meta_query

Not sure why this works, where the other query was failing. I’m not sure if it’s a bug that others are experiencing or not. Anytime I included any category “inclusive” arg, it broke my meta_query, but it didn’t seem to if i was “excluding” categories. So,…making an array of all category ids, then unsetting the … Read more

Retrieve posts in custom post type and specific taxonomies

Both get_posts() and wp_query() should be able to do this by passing the tax_query array into them. Example: $query = array( ‘post_type’ => ‘portfolio’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘clients’, ‘field’ => ‘slug’, ‘terms’ => array( ‘acme’ ) ) ), ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’ ); $posts … Read more

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