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.
146
votes
3answers
37k views
When should you use WP_Query vs query_posts() vs get_posts()?
It seems like half the tutorials in the codex and around the blogosphere use query_posts() and half use WP_Query. What's the deal?
48
votes
3answers
17k views
When to use WP_query(), query_posts() and pre_get_posts
I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
9
votes
1answer
2k views
Alternative to query_posts for main loop? [duplicate]
Possible Duplicate:
When to use WP_query(), query_posts() and pre_get_posts
I just noticed today that the documentation for query_posts() mentions some "disadvantages" of using query_posts ...
2
votes
4answers
6k views
Using WP_Query to Query Multiple Categories with Limited Posts Per Category?
I have 3 categories with each 15 posts, I want to do ONE query to the db bringing only 5 first posts for each category, how can I do it?
$q = new WP_Query(array( 'post__in' => array(2,4,8), ...
3
votes
1answer
740 views
Help to condense/optimize some working code
WordPress by default shows ALL posts to users who are Authors. I wanted Authors to only be able to see their own posts so I came up with the following code which works well.
Any suggestions to ...
4
votes
4answers
7k 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 ...
1
vote
3answers
1k 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( ...
0
votes
1answer
582 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 ...
0
votes
2answers
1k views
How to order posts by modified date without using 'query_posts'?
I have an example basic wordpress theme template here for you. First, please take a quick look at it to get an idea.
<?php
get_header(); ?>
<div id="primary">
<div ...
3
votes
1answer
870 views
hide other users' posts in admin panel
I intended to run a multi-author site, I don't want the posts from other authors to be shown in /wp-admin/edit.php page.
I managed solve this problem by the codes from this thread:
...
2
votes
1answer
965 views
Custom Post Type “Event”: chronological list of recurring events
i'm looking for a good and easy way to have a custom post type "event" that can have multiple dates. (I have tested about 20 plugins). I think i have no problem building a metabox allowing the user to ...
-1
votes
1answer
248 views
Integrating custom API for post content into Admin interface & Public Website [closed]
EDITED question to be more specific and added bounty in hopes someone has a solid coded solution:
So, here is an interesting task I have been trying to find a solution for. I have added a bounty ...
4
votes
2answers
3k views
query_posts() in function makes global $wp_query out of sync?
This has me stumped for a while already. Either I am missing something very obvious or something very not obvious. I am also not entirely sure if this has something to do with WP or purely PHP ...
3
votes
1answer
1k views
Display only the latest post from multiple categories
I have a jQuery slider at the top of my index.php, which works fine. The only problem is that I would like to use query_posts to only display the latest post from five different categories, and always ...
4
votes
1answer
3k views
Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
OK, so i'm messing with Custom Taxonomies for the second time and in both instances i've run into this problem where using the posts_per_page argument in either a query_posts or WP_query scenario.. ...
3
votes
4answers
3k views
How do I exclude a custom taxonomy from the post loop
Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I've been looking high and low, and neither SE, SO or Google seem to have a straight answer.
I know it can be ...
1
vote
1answer
187 views
Author List page: Exclude based on last post date
I have a Author page that I built using this code and it works fine. However, I have several writers that range from frequent to one-time writers. I would like to seperate out writers that have not ...
1
vote
4answers
1k views
Wordpress Posts Out Of Order after 3.1 Update
The first posts I wrote are now showing on the homepage. After Googling, the problem is because I am using query_posts to exclude a certain category on the main loop.
<?php ...
0
votes
1answer
103 views
How to know which one is the main query?
I just did an action on the query using pre_get_posts and it didn't work. When I removed the $query->is_main_query() it did work.
So, how do you know that what is the main query. I know there is ...
0
votes
1answer
68 views
order post my meta value m/d/y format with year as included value
current order:
01/01/2013
12/07/2012
12/08/2012
.
.
.
.
12/31/2012
-------------
01/01/2013 should appear last
My code:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$today = ...
0
votes
2answers
2k views
Get posts by meta data OR title
I have a working query that calls all my posts that have a certain meta value for one of two meta keys:
$term = $_GET['term'];
$args = array(
'post_type' => 'some_cpt_name'
,'meta_query' ...
2
votes
1answer
2k views
Loading Custom Post Type Events into jQuery-based FullCalendar?
Here is a question I have spent over 3 hours attempting to solve but each approach I take ends up not working out for me.
All I am attempting to do is utilize this opensource ajax calendar script:
...
5
votes
4answers
1k views
Display/query post formats
WP 3.1 has everyone excited, if somewhat confused, about post formats.
Enabling new post formats
The issue of enabling post formats has been covered at length. It's as simple as adding this line to ...
3
votes
2answers
2k views
Sort posts alphabetically by custom field value, insert divider between different letters
i'm listing all posts of my custom post type "person" alphabetically sorted by the custom field last_name on a page.
How would i insert a divider (e.g. an image of the letter) before a letter range ...
2
votes
4answers
2k views
How to return results of a get_posts() in explicitly defined order
I'm trying to create a loop of explicity ordered posts, for example:
<?php $args = array(
'include' => '1,3,8,4,12' ); ?>
<?php get_posts( $args ); ?>
The results are ...
1
vote
2answers
599 views
Using categories & “stickyness” together
I've got a custom query on my homepage showing all posts in a certain category. I need this query to respect sticky posts, but it seems from my research that category queries ignore stickyness. My ...
0
votes
1answer
479 views
Help altering a query to exclude all but standard post format
I feel like I've been banging my head against the keyboard for a week with this problem. I'm trying to change my current query on my home page to show only posts that are set as standard posts using ...
7
votes
3answers
7k views
Order by meta value or date?
Got a custom field called startDate but its only on a few events. I was wondering if it isn't set for a post I could use post_date to generate the posts list?
// if meta_key _postmeta.startDate isn't ...
6
votes
1answer
6k views
How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
I've been troubleshooting an issue over the past few days and keep going in circles. Could really use a fresh pair of eyes to help me answer this question...
So I'm working with a wordpress site ...
6
votes
2answers
3k views
How do I query by post format in WordPress 3.1
I am trying to query for all posts with a post format of 'quote.' I have added the post formats to my functions.php with
add_theme_support( 'post-formats', array( 'image', 'video', 'gallery', 'quote' ...
4
votes
1answer
2k views
Using meta_query, how can i filter by a custom field and order by another one?
With the following code (in functions.php) my posts (of CPT event) are ordered by _end_date instead of _start_date. What's the proper solution to this as of WP 3.1.3? Of course I'd like to avoid using ...
2
votes
3answers
1k views
How to get the parent's taxonomy?
I have 2 customs post type : "Artist" and "Concert",
the "Concert" custom post type is the child of the "Artist" custom post type,
the "Artist" custom post type has a "genre" taxonomy.
What I'm ...
0
votes
2answers
196 views
List users with the most total posts view
I'm asked by my friend to create a widget for his multiauthor blog. He wants to list 3 authors with the most total post view from their posts. I've got the job done for the post view using post ...
6
votes
5answers
4k views
Wp get all the sub pages of the parent using wp query
Here is my code
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page','post_parent'=>$parid,'orderby'=>'title','order'=>'ASC' ));
It displays ...
4
votes
1answer
3k views
How to filter custom posts by tags and custom fields?
I'm planning a site for a client who wants users to be able to filter upcoming events by the following criteria:
Type i.e. Comedy, Theatre, Music etc.
Date Daily or Weekend
Duration Daily or Half ...
3
votes
3answers
500 views
How do I create a random post that will last for a day
How do I create a random post but it shouldnt be change when the page is refreshed
I want a random post that will last for a day and after 24 hours or a day,
it will change randomly the post ,
...
2
votes
1answer
303 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
2answers
4k views
Best way to load page content in Fancybox popup?
I would like to have some links which load the page content of the page they reference to inside a Fancybox popup(pages like "shipping" or "returns", mainly text content).
I would create the pages an ...
1
vote
3answers
2k views
how to group custom post type posts by custom taxonomy terms
I would really appreciate if you could help me :) I'm very stuck and don't know how to proceed.
I have a custom post type called event and 2 custom taxonomies registered for it:
event_type with ...
1
vote
1answer
3k 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
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
3answers
1k views
Query on custom field count?
I have the following code:
<div id="pc" class="smartbar-content">
<ul class="smartbar-items">
<?php
$paged = ( get_query_var('paged') ) ...
1
vote
1answer
1k views
meta_compare seems to be treating values as strings instead of integers as expected
Trying to use meta_compare as suggested in the codex:
query_posts('meta_key=miles&meta_compare=<=&meta_value=22');
Here is my code:
global $wp_query;
query_posts(
array_merge(
...
0
votes
1answer
947 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 ...
0
votes
1answer
504 views
pagination in author.php template returns 404 error
Hi to the community!!!
I need some help with pagination in author.php template.
I have pagination working in all my loops except in authors.php that i get a 404 error.
In my settings/reading i have ...
0
votes
2answers
2k views
Sorting problem with 'query_posts' funcion in wordpress. Sort by custom field not working
0 down vote favorite
Hi, I am working with wordpress where i have a event listing system. There is a custom field in my post called starting_time which is unix timestamp. Now i want to short all ...
0
votes
2answers
1k views
Total Count of Posts NOT in Selected Categories?
I need to get the total number of posts that are not in selected categories.
I have category IDs of the categories that I want to exclude from count (in the variable $folio_cat_ids)
So far I have ...
8
votes
3answers
7k views
How to Get All Posts with any post status?
i am creating a frontend dashboard where i need to show all the post by the current user. So i need to show posts with all post status. Mainly published, trashed and the pending. I am now using ...
4
votes
2answers
405 views
Build a content and excerpt grid loop with paging and options for # of posts
What I'd like to do: on index.php, a loop that shows a selectable number of full posts using the_content and then below that shows a selectable number (the number of posts can be hardcoded in the ...
1
vote
1answer
134 views
Getting movie and serial on actor page
I'm building a cinema site, I came with a problem, let me explain:
Movies- are stored in Post's
Actors- are stored in Post Type - persoane ( taxonomy= lista)
Serials - are stored in Post Type - ...