"wp-query" ambiguously refers to one of two things. 1) WP_Query is a class native to Wordpress which allows users to query the posts database using a number of criteria. 2) $wp_query is the default object that holds the main query object on each WordPress page.

learn more… | top users | synonyms

1
vote
1answer
1k views

Using ajax with paging and a custom sub-query

I have a page that uses three queries to retrieve a variety of content. One of those queries grabs posts that are related to the topic of the page. Since these posts can be of all sorts and related ...
1
vote
2answers
179 views

Finding posts containing matching array elements in a meta field usign WP_Query

I have a metafield, that contains a series of options and writes the results to an array in a single meta field: array([0]=>'First', [1]=>'Second', [2]=>'Third', ); I find ...
1
vote
3answers
1k views

Custom URL parameters in template files

SETUP I want to pull a query variable from the URL and use it on my single post template (single.php). For example: mysite.com/2011/07/29/testPost/?myvar=someValue To do so, I added the custom query ...
1
vote
1answer
2k views

Query Custom Post Types & category_name?

I'm using jQuery Supersized to create a full screen image slideshow. The images are called from a custom post type called Slides. The code works fine but I want to be able to only pull in Slides in a ...
0
votes
1answer
802 views

Can serialized arrays in DB be matched against serialized arrays with meta_query?

Say I have an array of checkbox choices associated with a post (a custom field) stored in the database in serialized form. On my site, I present users with the same checkboxes and let them make their ...
2
votes
3answers
2k views

Check for featured image in WP_Query

Is there a way to filter posts by featured image when initialising a WP_Query object? Example $my_query = WP_Query(array("has_thumbnail"=>true)); or, more ideally $my_query = ...
1
vote
1answer
1k views

Order posts using a custom array

I have an array of post ids which I'm passing to query_posts using 'post__in'. My question is how can I use the order from my array rather than ordering by 'date' etc?
0
votes
1answer
218 views

Is there a function to get post info for any publish_status by post ID?

I'm trying to, essentially, check whether a post exists and if it does (in published, draft or auto-draft states) return the post info. I'm finding get_post() doesn't seem to work with drafts, and ...
2
votes
2answers
3k views

Advanced Tax Query

Below is my tax query, at the moment this returns all posts which have at least one of the specified terms. Is there a way I can have it return only posts which have ALL of the specified terms? ...
0
votes
2answers
2k views

Exclude Child Posts from WP_Query

How can I exclude child posts using wp_query? Given the following architecture: parent 1 child 1 child 2 parent 2 child 3 child 4 I'd like to only return parent 1 and parent 2, and exclude ...
0
votes
1answer
163 views

Is it possible to add an argument to a custom function added to a filter hook?

Example: I'm trying to modify an instantiation of WP_Query by using the posts_orderby filter like so: add_filter('posts_orderby', 'favorites_orderby'); $new_query = new WP_Query($args); ...
1
vote
1answer
419 views

How to pass the current content of $wp_query to a new page?

I am developing a Wordpress theme that uses a lot of AJAX. It is composed of two main pages: the index, which displays a list of posts, and a viewer (similar to single.php). When a post is clicked in ...
1
vote
1answer
118 views

How is WP_Query parsed to determine which template to request?

I noticed that when I changed the WP_Query to ask for a certain category, the page served was category.php. So I'm guessing there's a block of code somewhere that decides which template to serve based ...
1
vote
1answer
3k views

Refine search results using WP_Query

I am trying to modify (refine?) Worpress search results by using WP_Query, just as it's explained in the Codex. The snippet featured in that article is on the top of the Search Template PHP file, and ...
1
vote
3answers
2k views

Custom URl parameter

i have Wp blog that need to receive a custom paramter on category page for filter the posts like my rule. For example: http://mysite.com/category/teste?myvar=ABC How can I get the myvar from ...
0
votes
1answer
418 views

How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?

My goal is to return posts based on a specific price range using meta_query. The price in the admin that the user enters is a custom field, created using WPAlchemy. In the example below, the query ...
0
votes
1answer
2k views

How to make the 'request' filter work?

I'm trying to get a Page to display a custom query using the snippet posted here. The following is in my functions.php: function alter_the_query($request) { $dummy_query = new WP_Query(); // ...
0
votes
2answers
752 views

Custom query looking at multiple custom fields and properly sorting

For the past two weeks I've been looking for a way to create a query in wordpress that returns all custom post types where a meta_key "mytype-expired" is NOT set to "yes" and then order the results by ...
1
vote
1answer
365 views

How to make a second query offset -2 from current post

I would like a second WP_Query on a custom post type's single page to return 5 posts, starting with two before the current post, so that I get this: The-one-before-the-previous post Previous post ...
0
votes
1answer
541 views

Related “custom post type” using “custom taxonomy”

on my "Work" template used for the custom post type with the same name, I have the following code showing a list of titles for every "work". What I want to do is to display just on that list the ...
2
votes
1answer
7k views

How can i get count from query post

How can i get the row counts in query post like mysql count(*). $obj_name = new WP_Query($args); while ($obj_name->have_posts()) : $obj_name->the_post(); // here i want to predict looping ...
1
vote
2answers
1k views

how to search in custom fields & custom taxonomy for custom search

I have a custom search which is a form that submits to the same page and uses wp_query to filter the results for a jobs site that I would also like the keyword search to also search in custom fields ...
1
vote
1answer
375 views

orderby in custom WP Query does not work

I have this query: $new = new WP_Query(array('post_type'=>'support','order'=>'DESC', 'meta_key'=>'post_views_count', 'orderby'=> 'meta_value_num', 'posts_per_page'=>'20')); the ...
2
votes
1answer
55 views

Optimised Code for Pulling Taxonomy Posts

I have created a CPT called 'stores', each store has a taxonomy registered to it called 'store-type' (i.e. whether it's a fashion store, or kids etc). There is a third taxonomy 'floor'. A store can be ...
0
votes
2answers
475 views

Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?

I have an IF statement shown below that runs one of 2 custom queries, based on the url. The problem I'm facing is if the url contains pagination such as /page/2/, my query breaks because the url isn't ...
2
votes
2answers
1k views

How can I query posts from multiple roles?

I'm using the code below from another answer to query posts from 1 custom role, eg "friends". I thought I could just comma separate the roles to list posts from more than one role, but this didn't ...
0
votes
2answers
2k views

How to change a custom query into a standard loop?

I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query while ( $the_query->have_posts() ) : ...
0
votes
1answer
2k views

how do I exclude child categories from a wp_query?

I'm doing a category-based search that looks like this: $feed = WP_Query("category_name=noticias&showposts=3&order=DESC"); The problem is this also brings me posts from the child ...
8
votes
5answers
24k views

query_post by title?

is it possible to create a loop of posts using WP_Query or query_posts using the title? ie $args = array('post_title'='LIKE '.$str.'% '); $res = WP_Query($arg); // the loop... // trying this ...
0
votes
1answer
99 views

problem with the loop

Hello I am working with my own template, and also using the post-to-post plugin, I am doing the following, <ul> <?php global $post; global ...
2
votes
2answers
3k views

Improving WP_Query performance for multiple taxonomies

I have a site with several custom taxonomies, and have found that one of the slowest parts of the site is attempting to query with an OR across several of these at once. I'm using a WP_Query like so: ...
0
votes
2answers
3k views

Simplest way to query with blog_id?

What is the simplest way to query posts using blog_id? I have a post type called video that holds, not surprisingly, multiple embedded videos. Each post has a different video. I would like to ...
0
votes
2answers
846 views

$wp_query->current_post restarts from zero on paged pages

I know how to keep track on the 'index' of the current post when running the loop using $wp_query->current_post Bu this restarts the count from zero on subsequent paged pages. So if I have 20 ...
0
votes
1answer
149 views

My WP_Query didn't work after upgrading to WordPress 3.2

I created a custom loop using WP_Query for my featured content slider. <?php $slider_query = new WP_Query(); $slider_query->query("posts_per_page=5&tag=".(get_option('cgr_slider_tag'))" ...
0
votes
2answers
10k views

How to display posts month by month?

How could wp-query be used to show posts month by month, and have it only show the past year? Or is it possible some wp_archive hack could handle this?
2
votes
1answer
607 views

Wordpress: Keep order of query_posts list of post ID's using post__in

I need to request a certain list of posts in the order I want. I'm getting the posts using: query_posts('category_name'=>'cases', 'posts_per_page'=>5, 'post__in'=>$_SESSION['sorting'], ...
0
votes
1answer
823 views

Hide posts from users with a specific role

Simply put, I need to hide all posts on the frontend if they are written by authors with a specific role. The role I have created is called 'Suspended'. I'm happy with putting a simple IF statement ...
4
votes
1answer
3k views

WP_Query with checkbox meta_query

I have posted this on StackOverflow too, not sure if that's allowed - if not let me know and I'll remove one (I don't want to look like I'm spamming). Anyway.... I have a custom post type and have ...
5
votes
0answers
727 views

Sticky Posts & Posts Per Page [closed]

I notice that sticky posts will disregard the posts_per_page param? Like I have a query like $q = new WP_Query(array( 'posts_per_page' => 4, ... )); If there are 3 sticky posts, I will get 6 ...
0
votes
2answers
686 views

meta queries do 'either/or' checks

I have a meta_query like this , but 'relation' => 'OR' NOT WORKING, Does meta_query only do 'both/and' checks and don't do 'either/or' ? $args = array( 'post_type' => 'post', 'posts_per_page' ...
0
votes
0answers
644 views

Wordpress loop in post admin view

I'm trying to use the loop inside custom post settings. However this results in several errors the most common being the following: when I click on a post on the admin it always goes to the the last ...
1
vote
1answer
2k views

WP_Query: offset ignored when posts_per_page is -1?

Is it only me or this is what's happening? I just want to get all posts starting from a certain offset, like 10. Instead I get all posts starting from the 0.
0
votes
1answer
154 views

Run second query on page based on author of the first query

I have my single-property.php showing custom post type 'property', within this page I want to also show the custom post type 'agent' that belongs to the author of property, each author only has one ...
3
votes
3answers
7k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
1
vote
2answers
2k views

Wordpress WP_Query() Not working properly

We would like to know that how we occur error when we implement this code in our sidebar.php $categories = get_categories(); foreach($categories as $category) { ...
5
votes
1answer
885 views

how to show posts that are missing a meta_value

How can I build a query to find posts that DO NOT contain a certain meta key or meta value? for example: query_posts( array( 'meta_query' => array( array( 'key' => 'feature', ...
0
votes
1answer
534 views

search serialised meta_value for date value?

i've saved and array of 'open days' as a serialised array in a meta value. I was hoping i could then just search this field for the selected dates but i can't seem to create a match. serialised = ...
1
vote
1answer
812 views

How to order posts in wp_query by the user role (2 roles in array)

I'm using the following code from this answer: How can I get the last posts by user role ? <?php $friends = get_users( array( 'role' => 'friends' ) ); $friend_ids = array(); foreach( $friends ...
0
votes
1answer
549 views

How to order posts by custom WP role?

I currently have the following custom wp_query which displays posts from 2 custom WP roles, "custom_role_one" and "custom_role_two". It displays the posts from my custom post type of "listing". It ...
1
vote
4answers
1k views

Why does “Blog pages show at most” interfere with my custom wp_query?

I'm very new to WordPress, especially when it comes to creating a custom loop as per below. This works fine, however I'm perplexed why "Blog pages show at most" (under Settings > Reading) is ...