Articles of wp query

Related Posts Excluding Certain Categories

I’m using a related posts PHP WordPress query, but having trouble excluding categories. I’ve tried excluding via cat and category__not_in as well as both as and not as an array. What am I setting up incorrectly? <?php $orig_post = $post; global $post; $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] […]

Ordering posts by custom field and grouped by month

I need display all custom posts (event), order them by custom field (date) and group by month: September Event 1 Event 2 August Event 3 July Event 4 Event 5 I know, it is frequently asked question here, but despite the reading many similar issues, I can’t do anything meaningful according them. So all posts […]

Error in meta_query not get result

I have this WP_Query <?php $args = array( ‘post_type’ => ‘banner’, ‘posts_per_page’ => 25 , ‘meta_query’ => array( ‘relation’ => ‘AND’, array(‘key’ => ‘ads_status’,’value’ => ‘1’), array(‘key’ => ‘adsposition’,’value’ => ‘top’)) ); $slide = new WP_Query( $args ); if ( $slide->have_posts() ) : while ( $slide->have_posts() ) : $slide->the_post(); $yourfile = get_post_meta(get_the_ID(), ‘yourfile’, true); $adsposition […]

WP_Query for products always returns empty

I have a simple following logic: $args = array( ‘post_type’ => array(‘product’), ‘product_cat’ => 280, ‘posts_per_page’ => 3 ); $category_posts = new WP_Query( $args ); if($category_posts->have_posts()): $result = ‘<div class=”three-products”>’; while($category_posts->have_posts()): the_post(); $result .= ‘<div class=”one-product”>’.the_post_thumbnail( ‘thumbnail’ ).'</div>’; endwhile; $result .= ‘</div>’; wp_reset_postdata(); return $result; else: _e( ‘There were no products matching your criteria.’ ); […]

Getting the permalink to the latest post from a category

What’s the best way to get the permalink to the latest post of a chosen category? I have a page that I want to have several links to the latest post from different specified categories. Simple question, but I’m not sure if it’s even possible 🙂 Thanks!

Group posts by attachment meta key

I am trying to group posts by meta key. So far I am able to show all the posts with the meta key (‘grouping’) but with this it is listing the grouping with each post. What I want to achieve is list the grouping as a heading, then list all of the posts with that […]

Include tags in WP_Query

I found several posts about it. Others said that you cannot do it without a plugin and others that it is possible. However, I am not sure what is true 😛 This is my query and unfortunately, I cannot make it return objects with a certain tag. <?php global $query_string; $query_args = explode(“&”, $query_string); $search_query […]

Date and Category query with filter

I am a little confused by this. I have a query that finds posts within a category and date. I can filter the categories, but I have no idea how to filter by date. The query works. I see all of the posts I have queried, but I don’t know how to filter the date. […]

Paging + WP Query

On every archive page I’m either using WP-queries and no paging, or paging without a WP-query and a regular old “if(have_posts)” Now on one archive page I want to display more than 8 posts (8 is in settings for all my normal archive pages) So I thought about using a WP-query, but when I use […]

How to restrict search on a certain page to only return results against custom taxonomies?

On a specific page, I would like the search to be performed only against the terms from two custom taxonomies. Not the content or title. That is, the user is directly searching taxonomy terms. What I’m trying to do is completely rewrite the query for searches, but it doesn’t seem to work. function search_filter_get_posts($query) { […]