A generic term referring to the process of retrieving information from a database.

learn more… | top users | synonyms

2
votes
4answers
3k 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%' ...
2
votes
1answer
1k views

order by numeric value for meta value

I have read countless posts on ordering data by numeric value ( as opposed to string - it i have a numeric meta value and it gets ordered like this 1 11 12 2 233 etc as opposed to the way i want it I ...
2
votes
2answers
2k views

Alter query on edit.php

What's the best way to alter the query being run on the Posts Edit screen (edit.php)? The current method I'm using is by passing an argument to the global $wp_query like so: $wp_query->query( ...
2
votes
2answers
181 views

Automatically adding meta data to posts or multiple query help

I run an events company whose website uses a custom post type system for posts (blog), events and tickets all stored as CPT's in the DB. On the guestlist (which counts 'ticket' custom posts if the ...
2
votes
1answer
495 views

Perform query with meta_value date

I am trying to perform a query on a custom-type post using the value of a custom field. This field contains a string date: dd.mm.yyyy. The post type name is 'event' The custom field name is ...
2
votes
1answer
227 views

List the 5 most recent child pages

I created a hierarchical custom post type for a gallery. The parent pages are the galleries and the child pages are the albums. I want to display the most recent albums on my sidebar (so basically the ...
2
votes
2answers
286 views

Splitting the main query in multiple loops with query_posts and/or pre_get_posts?

I have a custom post type 'events', to which I have associated a custom taxonomy 'calendar'. The calendar has 12 fixed terms, for each month of the year ( 'august', 'october', 'november, etc.). I'm ...
2
votes
3answers
2k views

add spans and characters into paginate_links

I am using paginate_links on my custom page query. What I have already works sweet and this is the code I have so far... <?php global $wp_query; $big = 999999999; // need an unlikely ...
2
votes
1answer
753 views

orphaned taxonomy terms remove by sql query

I have 3 custom post types each of these CPT's have posts that are set to auto delete via a given time scale by cron jobs, thing is when they are deleted it leaves behind orphaned taxonomy terms in ...
2
votes
1answer
204 views

Save default value for empty or missing post meta

I am using WordPress and I am using a custom field that has the name ecpt_carprice for each post I am publishing, the field is saved in wp_postmeta the same as the attached image: Some of my cars ...
2
votes
2answers
386 views

Remove Unnecessary Mysql Query

my single posts is getting 31 query from mysql. I checked all queries. I saw this query. I am using last posts and categories widget. I think there query is unnecessary.How to remove theme Query: ...
2
votes
1answer
258 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
604 views

How can I query all users who registered today?

I'm trying to use meta_query to return all users that have registered today : $args = array( 'meta_query' => array( array( 'key' => 'user_registered', ...
2
votes
1answer
1k 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 ...
2
votes
1answer
453 views

Plugin similar to Taxonomy Drill-Down for custom fields?

Is there a plugin available that does for custom fields what Scribu's excellent Taxonomy Drill-Down (formerly called Query Multiple Taxonomies) does for taxonomies?
2
votes
1answer
1k views

[Plugin: Posts 2 Posts] How does it work?

I recently discovered Scribu's Posts 2 Posts plugin, which seems to be exactly what I was looking for in order to connect pages and posts for a big editorial website. But I cannot get it to work, ...
2
votes
1answer
72 views

Custom Post order for homepage

I would like to display a dropdown on the homepage which contains [most popular, most recent, trending] and when a user selects on of them the posts are page reloads and the posts are sorted in that ...
2
votes
1answer
279 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
335 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 ...
2
votes
3answers
732 views

Wordpress query by category, sorted by custom field

I have three custom fields set for each of the posts in the events category — year, month, and day. I am already querying for the events category, and now I'd like to sort the posts by the custom ...
2
votes
1answer
323 views

How can I get all posts data from within a paginated search result?

Let's say I'm doing a search on my site, and get 50 posts as a result. The pagination is set to 10 posts per page, so I have 5 pages of results. When I'm on the first page of results, if I inspect ...
2
votes
1answer
239 views

Multipart/formatted MySQL query problem

I'm creating a plugin and I want to automate the creation of a MySQL Trigger on a table. The problem seems to be that $wpdb->query doesn't appear to accept either multipart statements and/or formatted ...
2
votes
1answer
346 views

mysql query paging

Hi I have made an sql query that gets several posts according the parameters that i've selected. I'm showing these posts but the inner paging within wordpress doesnt do anything. It shows me that ...
2
votes
1answer
29 views

Filter Media Library by author or post_parent

I am trying to filter the Media Library so only media items that are uploaded by the current user OR children of the post being edited are visible. I've had no problem doing it if the conditions are ...
2
votes
1answer
162 views

Using Wordpress public query variables

Good morning. I am trying to query various Wordpress pages, using public query variables, for example http://dmkim1979.ru/?p=37 // single post http://dmkim1979.ru/?page_id=40 ...
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
1answer
835 views

How to List Events by Year and Month Using Advanced Custom Fields?

I have a custom post type "Kalender_item" with a custom Date Field (YYMMDD). I want to list all the posts on a page sorted by Year and Month. For example: November 2012 (all events that occure ...
2
votes
2answers
292 views

Grouping related postmeta data via SQL query

I am using someone else's WP plugin which stores lots of related data in wp_postmeta using an "artificial key". So effectively we hijack wp_postmeta to create a nested relational database. So one row ...
2
votes
1answer
235 views

Show All Posts Insert Edit Link

When I click to insert/edit link in the tinyMCE rich editor for a post, then click "Or link to existing content", it shows only posts that are live and published. Is there a way to get the list that ...
2
votes
1answer
38 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
2answers
1k views

Get category slug and display it on a query_post

I just read "How to create option page for wordpress theme" in wp.tutsplus.com - I have a problem with getting categories . there is two parts to my question - Part A - Get category slug and ...
2
votes
2answers
1k views

Next & Previous (Pagination in this case) Not Appearing

I am using a custom page template for my portfolio. The code is calling the correct number of posts per page but for some reason the pagination links won't show up :-S My query <?php $loop ...
1
vote
4answers
3k views

Export wordpress table to excel

I have created PHP scripts before to export a database table to .xls format like this: $select = "SELECT * FROM tracking"; $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ...
1
vote
4answers
2k views

How to tell if $query_var isset?

I tired to use isset($queryvar) but that didnt work, so I implemented my own function qv_isset, but it runs into a problem when $ch is set to 0. $cls = get_query_var('cls'); $ch = ...
1
vote
3answers
477 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 ...
1
vote
3answers
3k views

Custom Post Types, Page Templates and Pagination. Why do I get a 404 Error?

I have spent hours today on a maddening issue I was having with displaying a custom post type. Everything displayed beautifully, except the pagination simply would not work properly. I have a ...
1
vote
2answers
82 views

Is there a conditional tag for latest post or do i need a query?

I need to display an avatar in the post info position which i have written the code for but i only want to display it on the most recent post on the home page and not a specific post as this will ...
1
vote
1answer
995 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 ...
1
vote
3answers
3k views

Display page content AFTER a loop of posts

This is probably easy once you know but I'm having trouble getting the static page content to appear AFTER a list of posts. I'm using a named page template which displays posts as a slider and I want ...
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
1answer
210 views

Advanced Custom Fields - Query Efficiency

For testing purposes I have edited page.php to have nothing other than: <?php while ( have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php $site_options = ...
1
vote
1answer
146 views

Undefined WP_Query::has_posts()?

This must be wrong. I was testing something so I did: $queried_post = new WP_Query(array('posts_per_page' => 5, 'offset'=> 1, 'category' => 1)); var_dump($queried_post->has_posts()); ...
1
vote
3answers
340 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 ...
1
vote
1answer
118 views

How to optimize my query filtering out unwanted data?

I use get_posts ($arg); to query the post table. Usually I need only three fields: post_title, ID and post_excerpt. But the data returned are many more, including post_content that is usually huge. I ...
1
vote
1answer
776 views

WP_Query Performance Issues with meta_query

I'm working on a custom template for a new theme that uses a WP_Query instance to select posts from 2 post types with 2 custom fields that are NOT empty. Depending on the section of the site, a ...
1
vote
1answer
1k views

How to use wildcards in $wpdb queries using $wpdb->get_results & $wpdb->prepare?

I am attempting to make a custom search for BuddyPress groups. Here is my method: public function search_groups($string){ global $wpdb; $results = $wpdb->get_results($wpdb->prepare( ...
1
vote
1answer
728 views

Is there any need to use both wp_reset_postdata and wp_reset_query together?

Is there any need to use both wp_reset_postdata() and wp_reset_query() together? Is it a case that I would pick one of the two functions; is there any point in doing this after a query : ...
1
vote
2answers
292 views

How do I find if a page has a template?

So I'm doing a query like this: $the_query = new WP_Query( array( 'meta_key' => 'homepage', 'meta_value' => 'yes', 'post_type' => 'page', 'orderby' => 'modified', 'posts_per_page' ...
1
vote
2answers
3k views

How to query for most viewed posts and show top 5

Here is how I am getting the views for one post: function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); ...
1
vote
2answers
814 views

Query from a different database than the default

I'm making a layout for a wordpress page. The layout needs to connect to a second database (both databases are in the same domain). But the problem is, when i execute just the file it works. But ...