Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [query]

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

0
votes
1answer
567 views

merge two query arguments into one WP_Query call

I'm overriding WooCommerce's default search query to include searching by SKU as well. // default search query $query_default_search = new WP_Query( array( "post_type" => "product", ...
0
votes
2answers
547 views

Get first comment link on the post itself

I have this function and a link to a post: <?php foreach ($results as $id) { $post = &get_post( $id->ID ); setup_postdata($post); <li><a <?php href="<?php ...
19
votes
5answers
22k 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 like ...
0
votes
2answers
611 views

Conditional posts in WP_query for search

I have a custom post type that im trying to limit results in search. The CPT is a deal/coupon, with a start and end date for each of the deals. What I'm trying to do is only show these posts in ...
0
votes
0answers
14 views

SQL query that returns a list of duplicate posts IDs, comparing their post_parent and a post meta value?

I want to build a SQL query that would fetch all the duplicate posts; by comparing their post_parent and the 'link_url' post meta. ID | post_parent | link_url meta 1 11 ...
0
votes
1answer
817 views

Count posts for pagination

I'm doing the pagination for a web. < Previous (pagenumber) Next > is easy, already done. But now I need to add a selector to go to a page directly (ex: to page 7), to do so, I need to know how ...
0
votes
0answers
10 views

SQL to Query the db and return all posts and it's metas

I am trying to query the wp db and return all posts and it's metas. However, the return is very slow. Am I doing it the right way to get the most optimal results? Please see my SQL below: SELECT ...
4
votes
3answers
4k 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
1answer
7 views

Restrict WordPress search to a single ACF field

I've used the following filter to include an ACF field into my search results. add_filter( 'pre_get_posts', 'so_9224493_adjust_search_query'); function so_9224493_adjust_search_query( $query ) { ...
0
votes
1answer
12 views

Why pagination is not working with tax_query param?

this is my query: $p_query = new WP_Query(array( 'post_type' => $post_type ,'post_status' => 'publish' ,'posts_per_page' => $per_page // 6 ,'paged' => $page // 2 ,'...
4
votes
1answer
549 views

WP_Site_Query vs. WP_Network_Query in WordPress 4.6

Can someone explain the difference between WP_Site_Query and WP_Network_Query in WordPress 4.6? WP_Network_Query() : Core class used for querying networks. WP_Site_Query() : Core class used for ...
0
votes
1answer
9 views

Yoast primary category query modification

I have a problem with Yoast and displaying my primary category alongside rest of the posts from that category. Let's say I have 4 posts, all of them are lorem category and one post has set lorem as ...
0
votes
1answer
642 views

How to add parameters for custom post type

I need to add a parameter to this custom query below. post_type=customer-stories&tag=microsoft,google I now need to add a parameter that will allow me to customize how many of each type of ...
0
votes
0answers
16 views

Remove post name of custom WP_Query when using in pagination?

Is this possible? I am trying to get pagination working on my pages and single pages. It seems like it's working, as it recognizes how many pages there are and shows the URL. The problem: the URL is ...
0
votes
1answer
22 views

Returning a custom content types with meta values

I find myself facing a situation where I will have a bunch of custom post types and I want to select those with specific meta values. There is a slight wrinkle in that the value I want to select ...
4
votes
2answers
2k views

simple sql query on wp_postmeta very slow

I have a wordpress installation and I need this query on every post: select post_id, meta_key from wp_postmeta where meta_key = 'mykey' and meta_value = 'somevalue' I have 3M rows on that table, and ...
2
votes
1answer
2k views

How to Loop within a Loop (Display Children and then Grandchildren)

I am trying to develop a query for WordPress that will allow me to display a list of child pages with titles only, and then under each child page title, a list of grandchilden (children of the child) ...
1
vote
3answers
36 views

List of the years with posts presented

I need to get a list of the years with posts of given category. Like this: 2008, 2009, 2010, 2012, 2013 (if there were no posts in 2011, it's not included). I try this query, and it works — I get my ...
0
votes
2answers
32 views

wp query multiple values > display a specific value first

I have a query that get relationship fields for multiple ID. I get the ID of selected item, and merge it in an array with other ID's ex : my page relationship ID = 5 my other pages ID in array = 6,...
0
votes
1answer
546 views

Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice

Anyone encountered this issue? I have created a custom php script which adds a new post by using wp_insert_post() but everytime I run the code it creates a 2 new post where in it should be only be ...
0
votes
2answers
682 views

wordpress udpate query not equal to

I am trying to write update query where id is not equal to 5 i want output like this but not working. UPDATE `wp_messg` SET `is_read` = 1 WHERE `job_id` = 1 AND `biv_id`!=5 $id=5; $wpdb-&...
1
vote
1answer
584 views

I am trying to hide a custom post type category to logged in users with Pre_Get_Posts

I have a custom post type in my theme called portfolio. It's categories are called project-categories. I am trying to exclude a project category for logged in users. I cannot get this to work at all. ...
0
votes
0answers
13 views

How to find duplicate posts?

The query below returns the second and subsequent post duplicates. Can someone better with SQL help me tweak the query to return all posts in a duplicate set? The reason is each duplicate set on my ...
0
votes
0answers
39 views

Slow page loads due to WordPress Core Query

I have a page with many posts and every single page load is noticably slow. Hence, I have checked with Query Monitor the culprit(s) for the slow loading time and found that one query in particular is ...
0
votes
0answers
244 views

ACF Loop Relationship Field Posts by Custom Taxonomy Term

I'm using the 'Post 2 Post for ACF' plugin (https://wordpress.org/plugins/post-2-post-for-acf/) to link 2 ACF relationship fields, for 2 different Custom Post Types. Everything is working great but I'...
0
votes
1answer
839 views

WP Query - Search in title or author_name

My need is to have a WPQuery that searches for posts which title is 'test' OR author_name is 'test'. Here is the code I tried: $search_query = get_search_query(); $args = array( 'relation' =>...
0
votes
0answers
13 views

wp query et author

I try to display at the end of an article a post-type list of the same author. I try with this code, it works perfectly on the author page but not on an article add_action( 'elementor/query/offres123'...
0
votes
1answer
576 views

Creating a custom search for a specific post type

Ok, so we know Wordpress comes with a built in search form. However, I've created a custom archive page that lists posts from a specific post type. I would like to integrate a search box that only ...
-1
votes
0answers
10 views

How to set specific position in order

I want to list posts order by Date DESC , but I want to have possibility to set a specific position for a specific post. Thank you
0
votes
0answers
24 views

Database Query not accepting my WHERE LIKE wildcard in my PHP code?

I have a query that works fine when I run it in PHPMyAdmin, but does not return anything when ran via the website form post. I copy and paste the exact SELECT below, replace both$searchByText and $...
0
votes
1answer
40 views

Custom query pagination with php parameter as arg problem

I have create a loop with a custom query. This query contains a php parameters that i m getting from url with GET method. The problem is that the pagination (even if it counts the posts correct at ...
0
votes
1answer
690 views

Pagination is not working on custom query inside a custom home page template

I know this is a duplicate question. But to comment on existing question, I dont have enough points. So here we go.... Pagination is not working on custom query inside a custom home page template. ...
0
votes
1answer
665 views

Merge two queries and remove duplicate

I want to merge two queries together and remove duplicate. I got it working individually. Now I got it working together but the results are not mixed and the duplicates are not removed. So I got the ...
2
votes
1answer
1k views

Display related products with custom output

I'm trying to display the related products with my custom html output, unfortunately i'm kind of lost on how to do this. The WP_Query below displays the products that are in stock, what i want is to ...
101
votes
4answers
170k views

How to display SQL query that ran in query?

I have come across a function before that displayed the exact SQL code that was used. In a loop for example, but can't remember. Can anybody tell me that function?
-1
votes
0answers
9 views

set_query_var form wordpress dashboard

I'm working with template part to build a custom theme. I'm using the set_query_var() and get_query_var() functions to set some queries to get part of the contents that are present inside my templates ...
0
votes
1answer
2k views

How to execute a SQL-query which contains multiple queries using $wpdb->query?

I want to execute the following Query-String, which contains 2 separate queries using $wpdb->query: CREATE TABLE `foobar` ( `id` int(2) NOT NULL AUTO_INCREMENT, `foo` varchar(22) COLLATE ...
0
votes
1answer
854 views

Creating a Back button on detail post page to go back to blog page with same query strings and page id

So, I would like to have a back button on the single post page that can be dynamic to the point to where it knows where it is in the query and bring me back to the blog page on the right page number ...
0
votes
1answer
701 views

Query Pulling the same post twice

After seeking help and failing, I managed to write a query for Wordpress that does exactly what it's suppose to do, however it pulls the post that it's suppose to in twice. I've stared and stared at ...
3
votes
4answers
17k views

Sort posts by category name and title

Trying to figure out how I can output my posts based on category title (a–z) and secondly, the title of the posts within the category: A CATEGORY – A post beginning with a – Because I want to be ...
0
votes
0answers
11 views

sql query page listing with option selected

I want to separate a page page from the sql query. for example current page and last page with option selected. my listing page code <ul class="list-group"> <h2 class="h3">...
0
votes
1answer
664 views

Using wp_list_table how to trigger update function “inline”?

Ok, i have used wp_list_table to read data from a custom db table and i like to be able to update the database table by clicking the correspondig cell. Defaults are 0 and when clicked the value is set ...
0
votes
0answers
57 views

PHP Fatal error: Uncaught Error: Call to a member function insert() on null

Hi I have an error that it's: Call to a member function insert() on null that the function $wpdb->insert(); returns. Now, this is my array:  Array ( [title] => Huqvarna 610 cross blocco ...
0
votes
2answers
731 views

Query String for the WP_QUERY parameters

I don't know how to turn some WP QUERY parameters into url query strings. Most of them are straight forward, but there are some I don't know how to get working. For example, for these WP_QUERY ...
0
votes
0answers
13 views

Getting custom field dynamically from variable

I feel like this should be relatively easy but for some reason I'm lost. I'm trying to access an associated posts ACF repeater field based on what row is being outputted. Here's the query in ...
0
votes
3answers
967 views

Performance bug - slow DB query

Since 2017-09-26 I have terrible problems with performance on my website. Loading single post or any other page takes even 20s. I've been debugging it it found out, that the problems are DB queries. ...
0
votes
1answer
334 views

Custom filter in admin edit custom post type responding with invalid post type?

I am trying to add a filter to the admin edit screen for a custom post type called "trip" that I set up using Custom Post Types plugin. I'd like the filter to filter by the custom field added by ACF, "...
2
votes
2answers
67 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', '...
-1
votes
1answer
32 views

SQL Query : how copy all tags of post into their post content in wordpress by sql query

I want to copy/move all tags of a post into posts content, as text form not in a link form. For example: A post has: a title in title field, some content in content field (like: a ...
0
votes
1answer
31 views

Query where ANDing slug values not working

I realize this isn't the most elegant sql. I modified this query where the original query only selected from a single category (the slug field of the terms table). I am trying to obtain a result set ...