A generic term referring to the process of retrieving information from a database.
145
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?
10
votes
3answers
8k views
Pagination not working with custom loop
I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function:
<?php
$sixtydays = date('Y/m/d', ...
3
votes
4answers
728 views
the_date() not working
I am using wordpress 3.2 and I did a query post like this:
<?php query_posts("posts_per_page=1post=type&page=post_parent=10");?>
Then I try to echo out the date of this post I queried ...
1
vote
1answer
536 views
Show only oldest post by author
I am working with a heavily customized install of WP. I've set up a specific post type, taxonomy, and roles that gets to use just that post type.
Ideally, I'd like to restrict members of that role ...
0
votes
1answer
96 views
How do I sort multiples pages?
I want to use a dropdown to sort a list of posts in WordPress. The results will display on multiple pages. So how do I pass the query on to the second, third, fourth, etc. pages?
Here's an example of ...
0
votes
2answers
185 views
Duplicate posts
I'm currently working on a Magazine style website and on the main page I have three different sections where I display the latest news. Slider, latest news and more news.
The problem is I can't ...
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
2answers
506 views
Sort custom post type list table by display name of a user id stored as post meta value
I have a custom post type named domicile. Each post (domicile) has an owner (not the author). Owners are users with a custom role. I store the user id as a post meta value (dmb_owner) for the domicile ...
2
votes
3answers
1k views
get attachments for all posts of particular post type
I'm making a widget that shows a set of images from recent custom posts. I want to run the following query:
SELECT p.*
FROM wp_posts p
WHERE post_type='attachment'
AND post_mime_type LIKE 'image%'
...
0
votes
1answer
307 views
Custom Query: query by post custom meta data
So I have a custom post called event, but I need to query only those posts which have a custom metabox(is a checkbox) called `Show On The Homepage: and only if that checkbox is checked.
<?php
...
0
votes
1answer
459 views
Filter all queries with a specific taxonomy
Is there any way to filter all post queries and add a specific taxonomy? Case in point, I have a taxonomy object of "Region" with terms like "Global", "Americas", "Europe", etc. (Users designate ...
0
votes
1answer
143 views
Adjust the order for returned posts
I have written a neat responsive slider for my Wordpress featured articles (feel free to use it):
<?php
$responsive = 'on' != get_option('henrik_responsive_layout') ? false : true;
...
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' ...
6
votes
3answers
501 views
Order posts (across the whole site) by metadata date
My custom 'Home' page is set to sort my custom posts via the custom date field with this (updated to be custom named) code in functions.php:
// sort order for home page
add_action('wp', ...
4
votes
3answers
2k views
Optimize Multiple Taxonomy Term MySQL Query?
(Moderator's note: Title was originally: "query/database optimisation")
I'm written a function for a custom "filter" search panel that allows users to select terms from up to four custom taxonomies. ...
0
votes
2answers
2k views
wp_query orderby title and meta key value (WP3.1)
I have a taxonomy wp_query and i would like to order the list by title and by meta value (numeric value)
Have a meta value Interesting = 1 or 0 in the posts
Not so interesting posts would be at the ...
13
votes
4answers
1k views
Show a different number of posts per page depending on context (e.g., homepage, search, archive)
In the Reading Settings, there is place to set the number of posts shown that affects the number of posts shown in all contexts. I'd like to show instead a certain number of posts on the homepage, and ...
1
vote
3answers
221 views
Delete post revisions on post publish
Is it possible to delete post/page revisions from the database when a post/page is published?
11/05/12 Answer: See the plugin below by bueltge
I want to do this on a site with 5,000 posts and ...
0
votes
1answer
1k views
Query multiple taxonomy in Custom Post Type
Currently I use:
query_posts("post_type=listing");
to pull all entries of my custom post type.
But I have a taxonomy called status with the values of Available, Pending, Sold.
I only want to show ...
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
372 views
Why does `get_permalink()` produces an add. DB request without $post->filter?
I'm currently working on a custom loop/query where I need to add the permalink of a post to the array of posts I'm retrieving from the DB.
Sadly get_permalink() produces one additional DB request ...
2
votes
1answer
220 views
Adding posts of custom type into the main feed
I'm having some trouble with a subject that seems to be pretty basic, so I'm starting to feel (a little, only a little) dumb :-)
Here's the thing: I want my main feed to include the posts and other ...
1
vote
3answers
417 views
Possible to filter the posts or categories that XML-RPC users see in their mobile application?
Is it possible to filter the posts or categories that XML-RPC users see in their mobile application?
I have a plugin that hooks into pre_get_posts and list_terms_exclusions to do what I need it to ...
1
vote
3answers
395 views
Search and replace text across all posts
I had used the ZD Video Plugin for WP a long time, and now, since my move to WP 3.0.2, it doesn't work anymore. To embed a YouTube video using the plugin, I would just write
...
0
votes
1answer
503 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
3answers
5k views
Using nextGen Gallery.. how can I call a list of all Gallery Names?
I'm trying to make a nav to access all the different galleries on a single page.
Instead of hard-coding all their names out. I was curious if it was possible to make this dynamic and just call all ...
0
votes
1answer
443 views
Display Post by taxonomy and taxonomy child
This is a follow up to Display Post by taxonomy and taxonomy child if exist
I need to display a list of Accomodation, first by Type of Accomodation, then by Regions.
I have a post-type, called ...
0
votes
1answer
995 views
Custom Permalinks Break Search Pagination
So I'm having a weird issue that I've never seen.
I have a search.php set up like this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string . '&paged=' . ...
4
votes
2answers
266 views
How to display Section for certain time
i am building a News site. I want to display 1 featured post from "prime" category for only few hours. after it should be expired or disappeared from the section.
please have a look here u can see ...
3
votes
1answer
977 views
restrict_manage_posts not working in 3.3.1
I have noticed my custom taxonomy filters no longer work in the 3.3.1 admin as per these methods:
Adding a Taxonomy Filter to Admin List for a Custom Post Type?
I also discovered that to filter a ...
2
votes
1answer
145 views
How navigation works in custom loop within shortcode?
I am using a shortcode to display a custom query. The shortcode is use in page. Everything is fine, only the navigation that I can't get it working correctly.
Here is the function that I use to ...
2
votes
1answer
3k views
Get all image from single page using this query
I'm having some trouble with this sample widget code. I want to get all images (Minus the post thumbnail) from a page called "Gallery" but for some reason this is pulling all uploaded images from the ...
2
votes
1answer
613 views
query multiple taxonomy and show post count
I have custom post type 'Product',
and 2 custom taxonomies 'category' and 'product status'.
What i am trying to do is list categories in page template and show how many total products in category ...
1
vote
3answers
1k views
$query->query_var['post_type'] not set for pages
Bulding off of this response from @kaiser about being able to filter by post types on a search page, I wanted to be able to automatically add-in all of the public post types available. So, after some ...
1
vote
2answers
905 views
Count user posts by user ID, Post type and Post status
What I am trying to do is modification of this function on codex http://codex.wordpress.org/Function_Reference/count_user_posts Check the title adding post type support bottom of the page. The ...
1
vote
2answers
583 views
How do I search inside specific taxonomies in Wordpress
I am trying to search for posts in specific taxonomies but any time I search, I get results from all the other pages instead of Wordpress searching within the selected category in the taxonomy.
I ...
1
vote
2answers
399 views
Can't pass table to $wpdb->prepare
I'm having trouble passing a table variable to $wpdb->prepare(); Here is functioning code:
$table = $wpdb->get_blog_prefix( $blog_id ) . 'my_table';
$voters = ...
0
votes
2answers
97 views
$wpdb returns no results with SELECT query on custom post type, works on default post type
EDIT: Adding more background info.
I've coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID ...
0
votes
1answer
69 views
Specific Loop For 2 <div> Within Each <li>
I need to create a loop that can logically be described as the following for a carousel:
Requirements:
3 Loops
2 Posts Per Loop
No Duplicates
Order by Post Date
Visual:
< Start Loop #1 >
...
0
votes
1answer
129 views
Upcoming Event: How do I sort database by custom date field, but ignore past dates?
I am using an events plugin and struggling to get my database query to be perfect. The query is on the event-single.php template. What I need the query to do:
Query the "events" custom post type ...
0
votes
0answers
38 views
All in one event order by
Im using All in one event calendar. On my single event page I want to query some dates and sort them by start date. My query looks like this:
<?php $event = ...
0
votes
1answer
165 views
show posts only on homepage but using custom post type and taxonomy for query posts via url
I would like to do the following:
I have a index.php file in which I query all posts from the existing post_types. Like the code below.
<?php if (is_home()); { ?>
<?php
global ...
0
votes
1answer
108 views
wp remove query
i want to remove a certain query in wp 3.1
add_filter( 'query', 'remove_delete_7_day_draft_queries' );
function remove_delete_7_day_draft_queries( $query ) {
global $wpdb;
$q = "SELECT ID ...
0
votes
2answers
268 views
How to extract all ID variables from a query string?
What is the best php method to extract all IDs from a query string and display them in a comma separated list?
I have a function that grabs specific posts from the database and am trying to enter ...
0
votes
2answers
199 views
bulk post_content update
I need to replace all post_content in a particular tag/category to the desired one i have. is their a plugin to accomplish it or is their a query to finish this. Iam sick of doing this manually, is ...
0
votes
2answers
592 views
Different Main Navigation per category
I have a client who has the categories listed in the right-hand sidebar. He came to me today requesting a different "navigation" in the header for each category.
So basically, if you click on ...
0
votes
1answer
375 views
Query the Loop without breaking it
Im trying to make different querys in my category like one with a offset of post and one that shows one post but while it continues to go through the loop, this is what i have but the loop keeps ...
-1
votes
1answer
906 views
WP insert post PHP function dynamically generated Custom Fields
Further to my previous question WP insert post PHP function and Custom Fields
We have a working insert post function that can also send over custom fields without yet knowing the ID. Please see the ...