Questions tagged [query-posts]

Set up The Loop with query parameters. This will override the current WordPress Loop and shouldn’t be used more than once. This must not be used within the WordPress Loop.

Filter by
Sorted by
Tagged with
1 vote
2 answers
24k views

Setting posts per page in query_posts

Bear with me here.. The default posts per page in the admin area is 10. During some testing I wanted to change the posts per page for my custom post archive to 2 (in WP 3.1). The problem is that I ...
1 vote
1 answer
272 views

Query Page Content From Theme Options?

I'm trying to create a slider where you choose what pages are shown in the slider, using a theme options panel based on the https://github.com/vauvarin/options-framework-theme That lists the pages in ...
1 vote
1 answer
244 views

posts_per_page option limits the number of Gallery items

I have noticed that if I have a query where posts_per_page are set to 4, any (image) gallery that belongs to one of those posts will too have only 4 items (although when I create the gallery from Add ...
1 vote
1 answer
1k views

Displaying terms based on loop posts?

I have a shortcode that shows a loop for a custom post type: while ( $loop->have_posts() ) : $loop->the_post(); // do something endwhile; Some of the posts are in categories ($term->...
0 votes
1 answer
5k views

how to store wordpress loop in array?

I am working on a site. This site has a built in layout organize that uses a switch statement to organize data on a page. I want to use that to organize the homepage posts. Right now, there are 4 ...
1 vote
1 answer
97 views

Sorting a query Field by date

I have my site, which at the moment is display university open-days, at the moment they are sorting by order of page title, when actually I would prefer they sorted in order of date, soonest first, ...
0 votes
1 answer
142 views

If Query Post Returns 1 Post

I have been using Query Post for a newsticker which I have created so that the user navigate through the number of news by simply pressing Next & Previous buttons. But in case if there is only 1 ...
2 votes
3 answers
5k views

Post count per (day/month/year) since blog began

I'm looking to echo the number of posts per month since the blog began, and for months where there was no posts echo '0'. This is the output I want: January 1, February 3, March 8, April 3, ... ...
1 vote
1 answer
130 views

Hook to return true when the_post() is used in a custom while loop

I fetch external data like this, but I also added the_post(); while($slice = mysql_fetch_assoc($result)){ the_post(); rest of my stuff } I need a hook to tell me if the_post() returns true, ...
1 vote
1 answer
3k views

Multiple instances of nivo slider plugin

I’m using Wordpress as a CMS for this site http://www.seadragon.co.uk/new_site/portfolio.html ...and it’s the first time I’ve ever used wordpress so sorry if I get the terminology wrong.... My ...
0 votes
1 answer
301 views

using query_posts to pull posts out of a category in a while loop. Getting odd echo

I have a custom template file I've been workin on. I have this code performing a loop after it queries posts from a certain category. This works and I have each post configured with styled divs, but ...
2 votes
1 answer
48 views

How do I query for a post by custom field?

I have a custom field called "song-id" and I'd like to lookup a post by a song-id value. Can someone give me the code snippet for it? (bonus: also looking for a code to use the permalink in the post ...
1 vote
1 answer
338 views

Query posts by meta_key whose value is an array

Let's say I'm modifying the default posts query: add_filter( 'pre_get_posts', 'my_filter' ); function my_filter( $query ) { $query->set( 'meta_key', 'my_rating' ); $query->set( 'orderby', '...
2 votes
0 answers
457 views

Querying posts with meta value that begins with a certain pattern

I am trying to create a search filter using meta_query. The only problem I'm having now is that I can't compare with wildcards. I think that's how you word it? $keyword = 'sos'; $tlds = array('com','...
1 vote
0 answers
961 views

define orderby URL with meta_key=post_views_count

I want to make an url with meta_key=post_views_count. E.g: http://www.mysampleweb.com/?meta_key=post_views_count&orderby=meta_value&order=DESC So the posts should be ordered by Views. ...
2 votes
2 answers
6k views

How to modify the query to exclude posts by slug?

How can I modify my query in order to exclude certain posts by slug? Is it possible? query_posts(array('category_name' => 'Mycat', 'posts_per_page' => -1)); Ty
0 votes
1 answer
509 views

Why would post_type be ignored in this query?

In the following query, post_type seems to get ignored resulting in display of all posts from my installation. What have I done wrong? <?php function filter_where( $where = '' ) { $where .= " ...
1 vote
1 answer
2k views

Custom Query num_rows returns wrong amount

So I have a custom query that fetches all posts in a given category. I am trying to get the number of rows returned but it is giving me the wrong number. Instead of 11, I am getting 14. Does anyone ...
1 vote
1 answer
1k views

Possible to display posts containing a short code ?

i have some posts with a certain shortcode in them. unfortunately these posts are in different categories and contain different tags so i am not able to query them. is it possible that i run a query ...
1 vote
0 answers
2k views

filter custom field values $min $max

The user needs to query posts by entering a $minPrice, $maxPrice and a category value. Here is my query which returns no results: function result() { $result = array( 'cat' => ...
0 votes
1 answer
3k views

show all in query_posts on category.php?

I want to be able to switch back and forth by clicking an anchor tag preferably, between showing a subset of posts and showing all posts, the code I am using is: query_posts($query_string . '&...
0 votes
2 answers
713 views

Post per page not working if no category specified

I'm going crazy... <?php query_posts(array('cat' => 3, 'posts_per_page' => 1)); ?> This shows 1 post (there is two in the category) >> OK <?php query_posts(array('posts_per_page' =&...
0 votes
1 answer
157 views

Echo a numerical value in query_posts

I am creating an option page for one of my wordpress themes and I am trying to ask user to enter "Number of posts to show" - I am using "query_posts" to show posts This is the code I modified but ...
2 votes
1 answer
169 views

reference the current category being used in the category.php page

I have this code in my category.php file <?php query_posts( array('post_type'=>'featured' )); $featured = new WP_Query( array('posts_per_page'=>1, 'tax_query'=> ...
2 votes
0 answers
581 views

Query_posts and attachments

I need some guidance on some WP code. I'm wondering if it's possible to take this code (which is grabbing all the images from the posts across my site and dumping them out): $args = array( 'post_type'...
0 votes
2 answers
742 views

How can I improve the performance of this query_posts loop?

I created a WordPress page template to build a customised XML feed for certain WordPress posts on my site. Specifically, the page template renders XML and only includes certain custom post types and ...
0 votes
2 answers
2k views

How to query blogs posts of WordPress sub domain?

I am using WordPress 3.2.1 multi-user. I need to show posts from a specific sub domain in my home page, for example: http://mysite.com/sub-blog. I need to show posts from sub-blog in my home page. Is ...
0 votes
1 answer
250 views

query multiple posts by id using a string parameter, not array()

I'm looking for a way to query posts by id, and using a string as a parameter, instead of an array. Like this: query_posts('p=153'); But I need to get multiple posts. For example with ID 153 and 154....
1 vote
0 answers
157 views

Order by category titles

I have a category page called 'features' this is all fine, but the posts in the features category also belong to a certain genre of film, and it's this what I want to order the posts by on the actual ...
0 votes
1 answer
1k views

Want Page Descendants when using query_posts post_parent or child_of

I'm trying to use query_posts to list all descendants of a page ID. Using post_parent only lists the first-level children. This Trac ticket seems to address it: http://core.trac.wordpress.org/ticket/...
0 votes
1 answer
1k views

Displaying links to all posts of the same category on the post page

I want to display the links to all posts of the same category of the current post on that page. I wrote the following code in the single.php file. <?php $categories_of_this_post = get_the_category(...
1 vote
2 answers
1k views

Page title in post query

How do i add the current post/page title in a post query? I've tried this, doesn't work: query_posts( 'posts_per_page=10category_name=&' . $post->post_title); if (have_posts()) : while (...
0 votes
3 answers
260 views

How do I use pagination in WordPress?

I'm using the index.php file and editing this so that it displays two articles at a time. I'm using query_posts( $query_string . '&posts_per_page=2' ); before the main loop and it's displaying ...
0 votes
1 answer
202 views

Can't get pagination to work for sticky posts only

I don't get my pagination to work. I need to filter my posts on sticky posts and display only two per page. Tried almost everything but can't get it to work. It is totally ignoring my posts_per_page ...
0 votes
1 answer
1k views

Getting all ID's matching a title in a custom post type

I am trying to pull out all post ID's that have the same post title. This is in a custom post type called 'course-manager'. Here is what I have so far: $pages = array(); $args1 = array( ...
0 votes
2 answers
654 views

WordPress Custom Query to get Most Commented Posts in the Past 7 Days

I'm trying to do a query on wpdb to get the posts commented on most in the past week... Any ideas what I'm doing wrong? $querystr = "SELECT comment_count, ID, post_title FROM $wpdb->posts ...
1 vote
1 answer
80 views

Have parent category contain only one post?

Projects <-contains basic info about projects -Proj1 <-detailed info about proj1 -Proj2 <-detailed info about proj2 -Proj3 <-detailed info about proj3 I have a post attributed to the ...
1 vote
2 answers
884 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( ...
0 votes
1 answer
1k views

Single-page wordpress theme navigation

I'm trying to build single-page theme. I want user to navigate thru menu with anchors (for example <a href="#About">About</a>). I've extended Walker for wp_list_pages so it outputs anchors ...
0 votes
1 answer
27 views

Post not found when filtered by category ID

On my home page I am trying to filter by a category type and limit it to one post; but I keep getting "no posts found". Here is my following code: <?php query_posts('cat=34&showposts=1'); ?&...
0 votes
1 answer
234 views

Having trouble using this post category query on multiple pages?

I have three pages on my site (Listen, Read, Watch) which each query a different post category: "listen", "read", and "watch" respectively. I created three separate php files with their own unique ...
1 vote
1 answer
681 views

Display posts with tag that matches current post title

How would I show posts that have a tag who's name matches the title of the current post? For example if you are on a post called "Hippo" at the bottom of the page I would like posts with the tag "...
0 votes
1 answer
14k views

Add AJAX "Load more" on custom query block

I have a index,php with various new WP_Query all working ok, but in this block I need to implement that "AJAX thing people love - the load more posts": <h2>Latests articles <?php ...
1 vote
1 answer
625 views

Sorting multiple custom post types without a meta key/value pair by sort order

At this current moment. is it possible to sort multiple custom post/page types without a meta key/value? I'm looking to just sort the posts by page attribute order: What have i done so far? I've ...
0 votes
2 answers
109 views

Least Number of Loops to Create Custom Homepage?

I am trying to create a custom homepage where the site content is shown as follows... See image... https://i.stack.imgur.com/ykrdf.png With separate loops this is simple... 3 individual query_posts ...
0 votes
1 answer
566 views

Query Posts to fetch Posts with Unique Tag

I am trying to write a query post such that it returns a list fixed list of posts from a category along with any of the one tag associated with it. For eg: <?php $arg = array('cat' => '1','...
1 vote
1 answer
865 views

Authors List page - How to include only those with wp_user_level as Author

At my Authors template page, I want to show a complete list of Authors only (i.e. wp_user_level=2) the code I used is like this: $current = (intval(get_query_var('paged'))) ? intval(get_query_var('...
0 votes
4 answers
4k views

Exclude categories from postquery

I asked this question without a clue what was going on. I got an answer with the code below. It worked when I got it. I tested it with shirts only, assuming it worked with the other cats. it doesn't ...
0 votes
1 answer
173 views

Exclude All Posts Which Do Not Have A Tag Assigned

Basically I have regular Category Listings that include posts WITH tags and posts WITHOUT tags. I need to modify the loop so that it ONLY includes posts which have one or more tags assigned to them. ...
0 votes
1 answer
92 views

Change content off every sixth element

I would like to create custom post query where i will list all my posts in the list. Then the tricky bit is to add different content to sixth element off that list. So something like this <li>...

1
18 19
20
21 22
25