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.

learn more… | top users | synonyms

2
votes
2answers
741 views

Conditionally Query Custom Post Types by Post Meta for Blog Home Page?

(Moderator's note: The question's original title was: "Custom query: Show custom post types plus custom post type with post meta on blog homepage") I'm in need of help with a custom query. I have ...
2
votes
1answer
110 views

WordPress query for most recent posts from multiple categories

I have 5 categories. I want to query each category and get a list of the most recent posts from them. I also only want single post from each category, with no duplicates. Is there a way to do this ...
2
votes
1answer
321 views

How to implement time filter to show random post 1 month for one category and 3 months for other categories

I started to work on one website after another developer and there is problem with his "popular widget" which is basically showing 3 random posts from category. There is some Switch statement which is ...
2
votes
1answer
340 views

Using database meta_values to calculate new post order using pre_get_posts or a 'request' hook

UPDATE: I have worked out my implementation of the selected answer at the bottom of this post. I'm implementing a sorting algorithm based on Reddit's hotness algorithm, in addition to a time-decay ...
2
votes
1answer
1k views

How do I query a custom post type with a custom taxonomy?

For some reason I'm finding it a struggle to grab any posts using a custom taxonomy... can anyone unravel my stupidity? $args = array( 'post_type' => 'adverts', 'advert_tag' => ...
2
votes
3answers
303 views

Exclude category from loop not working

I have this code in my index.php file. I have a different template for a static home page, this is the blog page. I'm trying to exclude all posts with the category "new" which is tag_id "13" <?php ...
2
votes
1answer
959 views

Order by meta_key with two meta_queries

This should be simple, but I just can't pinned down a good example of the correct syntax to do this. I want to order by the specified meta_key with two meta_queries. The problem is query_posts ...
2
votes
1answer
260 views

meta_value_num sort glitch

i have a custom query, and I have a meta key that contains a sequence number: 1.1, 1.2, 2.1, 2.2... 11.1, etc the problem occurs when the numerical sequence gets in to double digits, ie. 5.11, 5.12, ...
2
votes
1answer
161 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
2answers
391 views

How to order results by date and meta key?

I'm using wp-postratings to rate posts which stores the rating as a custom meta value ratings_score. It gives you the option to use r_sortby to order the loop by highest rated but I want to give it a ...
2
votes
3answers
921 views

Pagination on custom query

I'm using the following code with query_posts to put together a custom search: $args = array( 'post_type' => 'species', 'meta_query' => $meta_query, 'tax_query' => $tax_query ); ...
2
votes
1answer
126 views

Can ordering post list by meta_value cause performance issue?

For some code refinement and to add new features to my plugin, I want to display posts ordered by specific meta column value like this; query_posts($query_string . ...
2
votes
1answer
426 views

Order by value in serialized custom field

Quite a pesky problem here. I've taken over a site that contains multiple information, serialised, within a custom field. For example: if ($new_query->have_posts()) : while ...
2
votes
1answer
644 views

query_posts sort in multiple directions

I'm trying to improve my post sorting by using multiple criteria, but I want specific orders for different values. For example, I have a meta_key called 'featured' that I want to move any post up to ...
2
votes
1answer
670 views

Search stores (custom postcode field) within 5, 10, 15 miles of user inputted postcode.. Code modification

I have been searching for a location search solution for wordpress.. The best semi-solution I have found is http://mondaybynoon.com/2010/02/22/store-locator-wordpress-pods The problem being is that I ...
2
votes
1answer
449 views

“NOT ONLY IN” taxonomy query operator?

I have multiple users adding content to restricted categories (using RoleScoper) in my WordPress setup that don't show up on the homepage (custom template with query_posts()). I'm looking for a way ...
2
votes
1answer
726 views

How to dynamically build a multiple taxonomy query loop within a post type's single loop?

This question is a little different then the others floating around here. The most similar one is "How to get the parent's taxonomy ?". I have a music cms setup that utilizes two post types: album ...
2
votes
1answer
161 views

advice on creating a 'related posts' query like the one used on stackexchange

One of the things that I most enjoy about the stackexchange website is the 'related questions' that show up on the sidebar when I am viewing a question (or show up as I am typing my question). It is ...
2
votes
0answers
86 views

Keep featured content post in homepage with original order

I'm searching how to keep the featured post in my blog homepage without excluding it from query post. My blog uses the Twenty Fourteen theme. I found this solution. Open the featured-content.php ...
2
votes
0answers
211 views

Display a query with multiple post types and same relationship on a single page

I am creating a client portal were my clients can maintain their projects and leave feedback in Wordpress. I have two custom post types called "Clients" and "Projects" and they each pull information ...
2
votes
1answer
3k views

Using OR conditions in meta_query for query_posts argument

I have searched high and low for this but I cant seem to locate anything. I am trying to filter some results and when I make an args array like this and pass it to query_posts I noticed that the ...
2
votes
1answer
346 views

order by meta_value serialized array

Hi I'm trying to pull posts using the wp query. Just one problem--I am trying to sort the posts alphabetically by a certain meta_value. Thing is that this meta_value is a serialized array. Is there an ...
2
votes
2answers
2k views

Sort Posts by Multiple Meta Values

1) Custom Post Type named "Buying_Locations" 2) Each Post has three meta values of: State, City, Store Name QUESTION: How can you show a list of these posts sorted alphabetically by State, then ...
2
votes
1answer
1k views

Page navigation doesn't show when query category

Problem: when I do www.example.com?cat=4 or choose category through custom menu or from category widget it shows only first page without navigation at the bottom, where it supposed to be. It's the ...
2
votes
2answers
2k views

get_query_var('paged') always returns empty

Putting this up after having hit a brick wall for possible solutions. Have a site with quite a few custom post types and associated custom taxonomies. To help make things easy, I'm using a unified ...
2
votes
2answers
202 views

Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]

I am currently trying to perform a custom query on the authors page (author.php). I have two custom fields for posts that I want to query against (post_photographer and post_videographer). What I am ...
2
votes
2answers
117 views

Multiple instances of Featured Image Query

I have some custom code built into the header of my theme that gets the featured image from a post, displays the image and links to the posts permalink when clicked on by a user. The problem I am ...
2
votes
1answer
39 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 ...
2
votes
0answers
1k views

query_posts with a custom post type, a meta_query and sorting by post date?

I've searched the archives and found questions similar to what I need, but haven't found exactly what I want. I've got a bunch of products that are sorted by a meta_key of country, and I'd like to be ...
1
vote
3answers
446 views

Insert all post IDs in new database table

I have a plugin which creates a new database table. Upon activating the plugin is there a way to insert all my posts ids into that table? Right now I'm using an action hook to immediately insert the ...
1
vote
3answers
20k views

Custom query with orderby meta_value of custom field

Aa you know, as of WP3.0 there are options for custom advanced queries, which is great. As of this, some query parameters of custom fields like meta_key, meta_value were deprecated for the new ...
1
vote
3answers
9k views

How to set posts per page using WP_Query()

I'm trying to set the number of posts_per_page dynamically using my own variable. This code works fine: query_posts( $query_string . "&posts_per_page=" . $myvar ) // then display the loop using ...
1
vote
3answers
4k views

meta query not showing any results?

I'm trying to show result for a custom field that is not empty on a custom post type but getting no results? <?php if (have_posts()) : ...
1
vote
2answers
8k views

use query_posts to return a post OR a page by ID

I'm building a custom homepage for a client where they want to have a few changeable boxes to link to specific pages, or posts, within the site. I've added custom fields to the homepage so that they ...
1
vote
1answer
1k views

Query posts by custom post type and custom taxonomy

I am writing a custom loop query to filter through a custom post type and custom taxonomy. I have replaced any variables with static values for the purpose of showing you what result I want. $args = ...
1
vote
1answer
3k views

Filter query_posts by tag slug on “Tag Archive” page (when tag is 2 or more words)

I'm using the following to bring up a tag archive page: <?php query_posts( "tag=". '' . single_tag_title( '', false ) . '' ); ?> This works perfectly for all tags of one word only, but any ...
1
vote
2answers
7k views

How to sort by meta value?

How can I sort by meta value? In meta value I have "price" (float). I make this query, but always get Sorry, no posts matched your criteria. $posts = query_posts( $query_string . ...
1
vote
1answer
6k views

Query Posts or Get Posts by custom fields, possible?

If I were to take a standard query post. <?php query_posts('post_type=payment'); while (have_posts()) : the_post();?> Only this time I would like to query the post by 2 custom fields that it ...
1
vote
2answers
63 views

Integrating post archive wtih another source and preserving date ordering

I'm pulling posts from Instagram into the WP basic archive view; but I want things to display in order of date, and not screw up paging (too much). The outcome should look like this: BLOG POST JUNE ...
1
vote
2answers
95 views

How do you Query posts with nothing in common?

We can get multiple posts manually in a page, but that's generated in a template, AFTER the default query returned something else (page/post, etc) How do you query multiple posts in a public query, ...
1
vote
3answers
2k views

query_posts and pagination, still stuck after much research

I need to paginate some custom posts...I can’t see why but I’m getting 404’s when going to the next page. Here’s my code: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( ...
1
vote
2answers
9k views

How to get posts published between a date and today?

Is it a way to get posts published between a date and today with query_posts() ? Example : All posts published since 2012-04-01 Thanks EDIT : How to add the filter date on this Query Posts ? ...
1
vote
2answers
2k views

Order by & include array by specific post ids

I have the following: <?php $num_cols = 2; // set the number of columns here $args = array( 'post_type' => 'testimonials', ...
1
vote
2answers
2k views

Adding Variables to post query

How do I add custom variables to the wordpress query without having to hit the database twice. In the example below I want to add some meta filters. All this code works fine but I have been running ...
1
vote
2answers
246 views

greatest() function returns undefined property

I'm using the mysql GREATEST() function to compare two table fields and display in a loop either one with the highest integer value. The 2 fields consist of vote scores for posts: UP or DOWN. ...
1
vote
3answers
74 views

Can I set and show “important” post in my blog?

I have the following doubt related to the WordPress posts showed in the home page. I know that in the home page I can show the latest published posts. But can I also show (before the latest posts) a ...
1
vote
2answers
518 views

Next/Prev posts on same page

Hello WordPress Users, I'm stuck with a problem building my wordpress website and I can't figure out what to do about it. Currently I'm showing 2 posts form the category 'News' at the page 'News'. ...
1
vote
3answers
76 views

Trouble Making WP_Query paged

I'm using the query below in the index.php file as the main query, whenever I try to go to the 2nd page I get a 404 error, I tried using posts_per_page but to no avail. <?php $args = array( ...
1
vote
1answer
2k views

How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling

I edited my loop in archives.php in order to work with pagination and with the Category Post List Widget. I basically pieced it all together from random code and ideas and am now so far from the ...
1
vote
1answer
203 views

How to fetch all posts in a category that were published between two given dates?

I need to be able to get all posts in the blog that were published in between two dates. The get_posts() API call doesn't seem to provide a method for limiting the time period of the returned results ...