Questions tagged [query]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
6k views

Get Terms by IDs with IDs order

I want to get Terms by IDs with IDs order. But that doesn't working, WP automatically change the order. My code- $catsArray = array(159, 155, 143, 153, ......); $series = get_terms( array( ...
3
votes
1answer
7k views

wpdb get posts by taxonomy SQL

I need a list of posts of a specific post_type plus the name of a custom taxonomy term. This is what I got so far SELECT p.post_name,t.name as clientName FROM $wpdb->posts AS p, $wpdb->terms ...
3
votes
1answer
1k views

Disable slow media queries?

When a user creates/updates a post within the admin, it takes between 15 and 30 seconds for that operation to complete. The culprit appears to be this slow query: SELECT ID FROM wp_posts WHERE ...
3
votes
2answers
2k views

Query by one meta_key and sort by another (possibly NULL value)

I want to query by 1 meta key, but sort by another key that may or may not exist, and then by post date So the end result would be something like: Meta Key A / Date 1 Meta Key A / Date 2 Meta Key B ...
3
votes
1answer
5k 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 ...
3
votes
1answer
3k 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 '...
3
votes
2answers
9k views

WP_Query ordered by custom field that is a date string?

Each of my posts have a single custom field that is a string of a date (not the date of the post). Instead of my theme's current query, which orders by published date, I want to order by this custom ...
3
votes
2answers
736 views

Sort X categories by last update and show image

I want to display X categories, and sort them by last update. I also want to grab the image of the latest post with the category. <img src="<?php echo get_image('article_image',1,1,0,NULL,$...
3
votes
1answer
2k views

Add multiple value to a query variable in WordPress

I am using the below code in functions.php to add custom query variables to my WordPress project. <?php function add_custom_query_var( $vars ){ $vars[] = "brand"; return $vars; } add_filter( '...
3
votes
1answer
15k views

Search custom post type by meta data

I have a custom post type 'Property' which my users need to be able to search by meta data. I have 3 search functions - 2 on the frontend 1 in the admin area - 2 of which are running as expected and ...
3
votes
1answer
206 views

How to make an activities stream mixing posts and comments?

What I'm currently trying to make is an activities stream wich list : The posts, the comments, both mixed between them and ordered by date. My idea is to make two queries, but i don't know how to ...
3
votes
1answer
609 views

Custom query_var causes displaying posts archive on front page

I'm having an issue which is caused by custom query var named date I've added using query_vars hook. When date parameter is present in the front page URL (https://example.com/?date=23.08.2016), ...
3
votes
1answer
198 views

WPDB Multiple site's posts and get featured images

I am using the code below to query 5 Wordpress sites for their posts, merging them into an array, sorting the array by date, and then displaying them: //SITE 1 $mydb = new wpdb('xxxx','xxxx','xxxx','...
3
votes
4answers
6k views

How to get link and title of next and previous post on single page

Guys How can I get the link and title of both next and previous post on the single page? Just like in the screenshot below. I try to use this but nothing shows up. $prev = get_previous_post(); $...
3
votes
1answer
1k 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 ...
3
votes
1answer
2k views

How to delete a transient on post/page publish?

I have a transient set for a custom query. It expires in 30 days. But I also need it to expire once a new post/page is published. So that the new published post/page is available in that custom query. ...
3
votes
1answer
937 views

Why does wordpress still strip my query var?

Im trying to pass a query var to a custom page template with pretty permalinks. So basically i have a page called "albums". And i want to pass a query var to that page called "type". So the non-...
3
votes
1answer
253 views

How to query for a week using key => value WP_Query argument notation?

I would like to be able to query for a specific year and week using WP_Query argument notation. I am using this notation as I would like the page to paginate. What's the correct "year" and "week" ...
3
votes
2answers
2k views

Very slow query

This query works, but it takes upwards of 20 seconds to run on a Quad Core dedicated server... How can I optimize this? $slides=get_posts( array('post_type' => 'any', 'numberposts' => 5, '...
3
votes
5answers
789 views

WordPress Number of Posts Not Changing With posts_per_page

I have thousands of posts that I am displaying on my home page. I want to control number of posts so for this I am using posts_per_pagebut it is not working for me. All other arguments works but ...
3
votes
1answer
167 views

How to find objects by terms

I am struggling with a search filtering. Firstly, my script is searching for users using natural search SQL. The query returns ids of users. Now I would like to filter them by terms which are assigned ...
3
votes
1answer
2k views

Query & Sort Comments by custom comment meta

I added a basic "favorite/recommend" functionality for posts and comments to a wordpress site I'm working on. I'm storing the total numbers of comment "likes" in a custom comment meta field (...
3
votes
3answers
1k views

Fulltext search in posts sorted by relevancy

I'm building a custom search page and what I need is to sort results by relevancy (eg. occurences of a keyword) Using MySQL docs I've built this query: SELECT ID FROM $wpdb->posts WHERE MATCH (...
3
votes
1answer
332 views

Custom Queries: Joining On Meta Values From Two Custom Post Types

Hi – I'm hoping this is the right place to be asking this question. I am in the process of moving my full football club website onto Wordpress, therefore using a single database for the information ...
3
votes
0answers
170 views

wp_enqueue_media() slows down my WP site

My website's been incredibly slow and I installed the query monitor plugin to learn more about the issues that caused this. When loading "New post" page, the following query takes 7,3662 (seconds?!) ...
3
votes
0answers
78 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
3
votes
1answer
446 views

Query Custom Meta Value with Increment

I have a Query searching for a meta value I have added to my posts (meta-select). I have it feeding out in a loop with 4 results. Let's say I want this loop to start with the meta value "2" and work ...
3
votes
3answers
3k 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
5answers
10k 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( ) )...
2
votes
3answers
607 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 [zdvideo]url-of-youtube-...
2
votes
3answers
4k 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 page-...
2
votes
3answers
6k views

Limit number of pages in pagination

I have more than 500 posts and I want to limit only 100 posts with pagination. So, 10 pages with 10 posts in each. Presenting you the code: $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' )...
2
votes
1answer
10k views

$wpdb->get_var not returning a result

I launched mysql and confirmed this query returns a result: mysql> SELECT * FROM wp_posts WHERE post_parent = 68 AND post_type = 'attachment' AND post_name = 'side-logo-auto2' LIMIT 1; 1 row in ...
2
votes
1answer
22k views

Problem with 'post__not_in'

I am running a custom query below each post, to get other post from its category. Now I want to exclude the current post. This is my Query: <?php // related_posts(); $exclude_post = $post->ID;...
2
votes
1answer
7k views

How to get the posts published in last two days using WP_Query?

I am trying to loop through all the post to get the top most shared posts on social network. I want to use the date_query parameter in the WP_query to get the posts of last two days , last 5 days, ...
2
votes
2answers
2k views

Get a user's most recent post title

If I have a user's ID, what's the best way for me to get the title of that user's most recent post?
2
votes
3answers
7k views

view queries made?

I know I can use get_num_queries() for the number of queries. However, how can I see what queries Wordpress actually makes? I've tried using $query but that didn't work.
2
votes
2answers
576 views

Query WooCommerce orders where meta data does not exist

I'm trying to fetch all my WooCommerce orders where some additional metadata is equal to not empty. $orders = wc_get_orders( array( 'orderby' => 'date', 'order' => 'DESC', '...
2
votes
2answers
122 views

get_the_foo() in the loop - does it perform another query?

I'm unclear on the get_the_foo() style of functions, for example get_the_permalink(). My main question is: when this is performed in The Loop, is another SQL query executed (besides the original ...
2
votes
1answer
3k views

If No Search Results, Show Posts from Alternate Search Query

I have a pretty standard loop which outputs "Sorry, No Posts Found" when a search result comes up empty. if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( 'templates/...
2
votes
2answers
852 views

How to order WP_User_Query results to match the order of an array of user IDs?

I'm using WP_User_Query to get a list of users from my database. I'm showing specific users only via use of the include parameter. For example: $args = array( 'include' => array( 1, 3, 5, 99, ...
2
votes
3answers
2k views

search through post-type attachments titles

I have a page where I show all the attachments of a page in a table which has id=10. I have hundreds of attachments and I would like to implement an AJAX search form that uses the title of attachment ...
2
votes
2answers
8k views

Query posts from current year

I don't quite get why this isn't working. I'm trying to use the following to only show posts from the current year on the front page: <?php query_posts( "&year=$current_year&order=DESC"); ?...
2
votes
4answers
7k views

wp_dropdown_categories with multiple select

in the search box I would like visitors to be able to search for more than one location (houses). The code right now is: <div class="col-md-3 col-sm-6 col-xs-12"> <label for="...
2
votes
1answer
2k 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 ); $...
2
votes
1answer
3k 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 $...
2
votes
1answer
2k 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 ...
2
votes
2answers
6k 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 ...
2
votes
3answers
6k views

Custom Select Query with Custom Post Types

Have been trying to figure out the issue with this for the past hour, but hitting a wall. Basically I'm just trying to query my custom post type based on some custom date fields and then displaying ...
2
votes
1answer
2k views

Date query year and month OR just year

I am a bit stuck with setting up this date query. I am using a dropdown select box to allow the user to choose which date archive they want to view. It works for the months, but when I select the year ...