"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

0
votes
2answers
422 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
1k 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
1k 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 ...
5
votes
4answers
20k 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
2k 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
760 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
8k 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
568 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
748 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 ...
3
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 ...
4
votes
0answers
642 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
679 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
602 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
150 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 ...
2
votes
3answers
6k 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
1k 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
819 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
494 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
738 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
533 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 ...
0
votes
1answer
2k views

How to count post type that has a particular term?

What is the best method to count the number of posts in a post type that have a particular term? I don't believe get_posts accepts a term query and I have had no luck with new WP_Query, though I might ...
0
votes
2answers
402 views

How to query the latest 5 posts and sort them by title?

I'm looking to draw a menu listing of the latest "n" number posts, where the number "n" will be a user defined setting stored as an option. n = 5; //Pull the latest 5 posts from the database. The ...
0
votes
1answer
1k views

If have posts a week old, display, else display a different loop

This is what I have. <?php $week = date('W'); $year = date('Y'); $projects_in_news = new WP_Query( array( 'post_type' =>'news', 'posts_per_page' ...
3
votes
2answers
262 views

Identify which loop you are hooking into; primary or secondary?

What is the most efficient way to determine which loop I'm in? I have a few plugins that alter the query by hooking into various parts of WP_Query::get_posts(), through the usual suspects, ie ...
3
votes
2answers
4k views

WP_Query and next_posts_link

I cannot figure out how to make next_posts_link() work within my custom WP_Query. Here is the function: function artists() { echo '<div id="artists">'; $args = array( 'post_type' => ...
1
vote
2answers
654 views

cannot get multiple loops using tax_query

I am trying to get three loops to display. they all belong to the same post type and the same taxonomy family. but i'm trying to separate the taxonomy by three different values. $argsOwners = array( ...
1
vote
1answer
186 views

How does order=asc effect a wp_query (its acting pretty weird in a loop)

I have a wp_query for a custom post type: events. I have a seven day calendar that is showing featured events on a page. Here is the wp_query and supporting code: https://gist.github.com/1030760 ...
4
votes
2answers
2k views

Get posts by menu ID

I'm a little stuck here. I have a menu in Wordpress with some posts in it. What I would like is to retrieve all the posts as objects. I think I'm pretty close, but the SQL query doesn't seem to work ...
1
vote
1answer
4k views

how do we display all posts from a particular category in homepage?

I am trying to show all the posts of a particular category on my home page. There are over 70 posts in that category. I would like have a pagination so that only 10 posts are displayed and have ...
1
vote
1answer
595 views

3 Columns, 3 Categories, One Archive, and Pagination

I have three columns, each displaying 2 posts, each from different categories and each being a new query. These three columns are shown on thier parent category page, which is set to display 6 posts ...
8
votes
1answer
11k views

WP_Query by just the id?

In the codex for WP_Query I see you can query by 'page_id=7' for pages or by 'p=7' for posts... is there a way to get a 'post of any post type' by ID? like 'id=7'—that will get it no matter if it's a ...
0
votes
1answer
131 views

How to use rewind_comments() - when and how to use it?

I've never messed with the comments loop before, but I'm trying something out here. Basically, I have my comments form in a popup iframe, an ajax action which handles the form submission, inserts the ...
1
vote
2answers
418 views

Display both standard posts in a specific category along with a custom post type in a single loop?

I'm building a content slider that needs to show posts from a custom post type called "Features," and also show standard blog posts that are assigned to a "Featured" category. I'd like to do this ...
1
vote
1answer
202 views

Metadata Query when storing data as array possible?

Suppose I store all my post meta data in an array like $meta = array( 'img' => '', 'caption' => '' ); update_post_meta($post->ID, 'theme_banner', $meta); Can I query posts where ...
0
votes
1answer
426 views

Trouble passing attribute into shortcode function

For some reason the WP_Query instance in my shortcode function won't take the query attribute sent from the shortcode. The shortcode is like this: [postlist query="post_type=any&posts_per_page=5" ...
1
vote
1answer
580 views

How can I filter by slug depending on language selection

I'm new to this site but looking at the quality of answers provided here I will be here for a long time :) Ok, first a bit of info: I'm developing a bilingual website (English & Japanese) using ...
1
vote
1answer
522 views

On Taxonomy Template page, want to add Post_Type

I have a custom taxonomy template page in my theme. Essentially, when someone clicks on a term link into this taxonomy, I -ALWAYS- want to add a specific post-type to the query. I'm not entirely ...
0
votes
1answer
710 views

How to make a query returning pages from multiple parents

I'd like to make a query that returns the children pages of various parent pages. Unfortunately the post_parent attribute of WP_Query accepts only one value. What do you suggest ?
0
votes
1answer
228 views

How can I build a query that returns all attachments of a page and it's children pages?

I'm using this query to return attachments of a page. $args = array( 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment' ); Is there a way to ...
2
votes
1answer
1k views

How to filter a dd/mm/yyyy date from a custom field in a query

I'm trying to build a query in order to sort some posts by a date custom field, where the dates are formatted dd/mm/yyyy. It works by querying the database directly with get_results like in this ...
0
votes
1answer
474 views

how to put thumbnail below category's title?

Edit : ok everything works fine : i finally had to use taxonomies and get_terms, and putting everything in divs work better than lis. Thanks for your help. Hi, i have a problem with the categories ...
3
votes
2answers
2k views

Custom post type archive 404's with paginate_links

im using paginate_links function to create pagination on my custom post type archives, no matter what i do im hitting 404 errors when going to view page 2 (ie clicking to go on one page in the ...
1
vote
2answers
3k views

query_posts: how to show all 'meta_value' containing a specific word?

How could you display all the post in a loop with a (custom) meta_value containing a word/phrase? for exemple get al the post where meta contains 'test'. ...
3
votes
3answers
2k views

querying with custom meta field with meta_query

How do we get posts where the meta key does not exist in a post. I have created a meta_key video. and i want to be able to get some posts with WP_Query where custom field video does not exist or is ...