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

learn more… | top users | synonyms

1
vote
1answer
129 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
893 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
750 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
316 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
7k views

Get Featured Image via direct sql query

I know you can use the wordpress methods for getting a featured image, however with this particular project I need to get the featured image via mysql query. Can anyone point me in the right ...
1
vote
2answers
890 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 ...
1
vote
2answers
199 views

What is considered a default query for the request filter?

As stated in one of the answers in this question and in the codex entry for the request filter, said filter gets called only in a default query, such as the main query used for a loop. My question ...
1
vote
1answer
1k views

$wpdb doesn't appear to work on page inside of a plugin

I have a plugin folder foobar. Inside this plugin I have a page called foobar.php. Inside this page I have global $wpdb; $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : ...
1
vote
2answers
797 views

Selecting New & Edit Page for Custom Post Types

I'm probably missing something unless it's really not possible, for some reason I can't get my function to only execute on the new and edit page of a custom post type (the new not being a problem): ...
1
vote
2answers
55 views

Select Multiple meta_value from WP DB; Single Query

I am trying to retrieve each user's first and last name, phone, email, and address from the usermeta table. I'm having trouble selecting multiple meta_values, each with its own meta_key, using a ...
1
vote
1answer
51 views

Query posts by content lenght

I am using the code below to pull a random post of my site every 6 hour. if ( false === ( $social_trans_post_id = get_transient( '$social_trans_post_id' ) ) ) { $args = ...
1
vote
1answer
65 views

Only display a certain number of posts, dependent on how many posts there are available in a query

I am trying to write some code for a slider of posts, at the moment my code involves two WP_Querys, one inside the other, but I can't help feeling there may be a more efficient way of doing what I'm ...
1
vote
2answers
57 views

Querying Term Posts in Loop

I'm trying to show my CPT Category along with any posts associated with it below the title. I have the first loop fine: <?php $cats = get_categories(array('taxonomy' => 'custtax', 'orderby' ...
1
vote
1answer
74 views

if/else on custom query gives 200 OK when condition not met?

What? I am modifying my theme to show comments of a post on a separate page. How? Mostly based on this answer but with improved checks and code. So this is what my page-comments.php (kinda) looks ...
1
vote
1answer
193 views

How to debug a blank page?

I'm not being able to load this page, although I can easily load all other posts that load the same custom post type template (please look for "// From now on, WP is throwing a blank page" on that ...
1
vote
1answer
161 views

Wordpress custom archive page

I am trying to build up a custom archive page. However, I would like this archive page to skip the first 5 posts. I've been able to accomplish this with the offset property. However, the pagination ...
1
vote
1answer
815 views

WP_Query: query posts by ids from array?

I did quite a bit of research but can't figure why this wouldn't work for me? echo print_r($rel); // Array ( [0] => 63 [1] => 87 ) $args = array( 'post_type' => array( 'post' ), ...
1
vote
1answer
1k views

Custom search page and search by title, content and tag

Can someone review my code , I need to know better solutions or any bug. Okey ! , I made a PHP file to get search results by parameters and search by title , content and tag PHP's head look like: ...
1
vote
1answer
468 views

Recreating the hierarchy of taxonomies for a dropdown form menu?

I have a form that contains a dropdown menu. This form is on a page form.php and is not part of my theme. It exists outside of my site. This dropdown menu contains my list of values for a custom ...
1
vote
2answers
211 views

Wordpress - query 5 posts with a specific post in top

Many searches and tests but in vain, I need an expert to rescue me. I need a custom post query in worpdress, which returns only 5 posts starting from a specific post. In other terms, there is a div ...
1
vote
2answers
2k 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
4k views

How do I search events between two set dates inside WP?

I am building a WP site with an events feature. The events page was made with custom post types. I want to make it possible for people to search/ filter events by dates. For example, they can search ...
1
vote
2answers
285 views

Query all posts which do not have tags assigned to them

Is there a way to query posts which do not have tags assigned to them? query_posts('tag='tag_exmaple'&posts_per_page=-1'); Ty very much!
1
vote
3answers
206 views

Huge amount of queries on my site

My site is reaching CPU limits all the time, I just ran Debug Queries and got more than 4000 queries, no wonder site is slow.
1
vote
2answers
2k views

Wordpress Orderby Numeric Value Not Working

I am trying to get all products from the wpsc-product post type and then display them by a custom meta field called release_date_year. However, it doesn't appear to be ordering my posts by this custom ...
1
vote
1answer
414 views

Disallow categories from this MySQL query

I'm trying to modify a plugin that generates an archive listing so it shows only one category, making it a single category archive. The old version of the plugin used a get_posts query, and so it was ...
1
vote
1answer
204 views

WP database error for comments_popup_link()

I'm using the comments_popup_link() function to show the number of comments for each post in a loop. <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if ( ...
1
vote
3answers
130 views

How to echo excerpts with wp_list_pages?

I've tried to echo excerpts in wp_list_pages with the code below. It works, but only for one of the child pages. How would I echo the excerpt and title for each child page? <?php $children = ...
1
vote
1answer
137 views

Should 'setup_postdata()' be reset with 'wp_reset_postdata()'?

Starting with an example makes more sense, so here's an example function: function seo_meta_tags() { global $post; if( is_singular() ) { setup_postdata( $post ); ...
1
vote
2answers
127 views

is_archive() doesn't work on public query var archive pages?

Public query vars are those available and usable via a direct URL query. E.g. example.net/?category_name=tech&tag=gadgets But doesn't example.net/?category_name=tech&tag=gadgets show ...
1
vote
1answer
36 views

How can I get a list of comments by target

I've been looking at the classes WP_Comment_Query and WP_Meta_Query but to be honest, I can't figure out how to use them together. I want to query the database for comments where wp_posts::post_author ...
1
vote
1answer
174 views

How to tune search argument in WP_Query to show only exactly the same results?

Right now I am using this: $args_search = array( 's' => $search, 'post_type' => array( 'post' ) ); $wp_query = new WP_Query( $args_search ); But the problem is that it shows ...
1
vote
2answers
51 views

Make one query for adding entries to database

I have a situation where I need several entries to be added to a database table (sometime a few hundred), but using $wpdb->insert() (and $wpdb->update() where edits are necessary) is running ...
1
vote
1answer
48 views

How can I sort homepage by a meta value?

I am trying to sort my home page posts by a custom meta value. I've been told I should use pre_get_posts but I seem to not be implementing it correctly. This is what I am doing: ...
1
vote
1answer
807 views

WordPress Loop: List All Posts by a Category & Subcategory

I want to display all post under a category and all subcategories under the parent categories. But couldn't find proper suggestion over forum or failed to understand the solution. It's possible to ...
1
vote
2answers
275 views

Disable the MySQL query in the main query

I would like to disable the MySQL portion of the main query, i.e. I want every step to be followed on this page EXCEPT step 4.3: http://codex.wordpress.org/Query_Overview What's the easiest way to go ...
1
vote
1answer
903 views

How to query a custom post type with a taxonomy filter but display post type archive page?

I'm filtering the main query of Jigoshop with my own taxonomy with this hook (The file responsible for Jigoshop queries that I'm hooking, Jigoshop hooks onto WP 'request' filter): add_filter( ...
1
vote
1answer
278 views

Show how many images are attached to a post/page on compose page

On the front-end, I'm using a query to show all attachments attached to the current post. However, on the compose page, there's no way for a user to see how many images are attached without opening up ...
1
vote
1answer
184 views

Loop after page content

I just upgraded to 3.4.2 from 2.9 (i know, i know, but if it ain't broke...) I have page templates that are (or at least were) set up to display the page content first, then start a loop of posts, ...
1
vote
2answers
476 views

Order query by post meta value

//Displaying latest post per author on front page function filter_where($where = '') { global $wpdb; $where .= " AND vipwp_posts.id = (select id from {$wpdb->prefix}posts p2 where ...
1
vote
1answer
894 views

Display category posts grouped by taxonomy

I'm working on a project where I use the default posts as "Products", default category as "Application" and a custom taxonomy called "Groups". I want to list "Products" by "Application" ...
1
vote
1answer
255 views

Pull post meta with post_query?

I'm building a custom index loop that just uses query_posts at the moment. The issue is that inside The Loop, I have to then query for the post meta data (with get_post_meta), which I believe has ...
1
vote
3answers
3k 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
521 views

Get the most popular terms for a custom post type

I’ve hit another small rock in my current project! I’m trying to list (and link) to the archive page for the top 4 most used terms for a custom post type. I have this; ...
1
vote
1answer
1k views

How to display posts under a specific subcategory of a given category

after a long search online I have decided to post my problem here in the hope of getting a solution to this issue. Well, I have a custom post with various categories (novels, books, magazines etc..) ...
1
vote
2answers
4k views

get post id using the $query_vars variable

How can I get the ID of a post (or page) based on the $query_vars variable? I want to do something like $query_vars['post_id'] But I don't have a reference page that has the list of $query_vars ...
1
vote
2answers
1k 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
225 views

Tricky WP Query

I am trying to use wp_query (or another native Wordpress query class) to do the following: get all posts WHERE ( post_type = 'post' AND category = 7 ) OR ( post_type = 'case-studies' AND meta_key = ...
1
vote
2answers
469 views

Conditional custom field query

I'm working on a job board-type site, and the client want to sell featured posts. They want the featured posts to expire from showing up in the "featured" section after a predetermined period of time, ...