Questions tagged [query]

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

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 ...
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
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
13 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 ,'...
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
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 ...
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
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
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'...
-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 $...
-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
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
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
0answers
58 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
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 ...
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 ...
1
vote
1answer
56 views

Get stock by custom meta field on all Woocommerce variable products

In WooCommerce, I have a custom meta field "Brand" on my products, and each product is assigned with one of the Brands. Now I want to get total stock for each brand from all products and I have only ...
0
votes
2answers
16 views

correct validate and sql query

Is this method of operation on the database is safe and correct? if(isset($_POST['name'])){ $table = $wpdb->prefix.'_my_table'; $post = trim(sanitize_user($_POST['name'], true)); $...
1
vote
0answers
27 views

get search results from only specific page name in wordpress

I have created a page by using add_submenu_page: add_submenu_page( "pharma-plugin", // parent slug "All Trade Name", // page title "All Trade Name", // menu title "manage_options", // ...
0
votes
0answers
17 views

Create a custom table with column as an index

I want to create a table in my wordpress database with a column that is an index. But I can't seem to make it work with this code: $table_name_t2mtokens = $wpdb->prefix . "t2mtokens"; $...
0
votes
0answers
28 views

Duplicate posts when using pre_get_posts for author.php

I'm trying to change the main query into the author.php but there are some duplicate posts?! How can I fix it, Thank you! function change_author_query( $query ) { if ( $query->is_author() &...
0
votes
0answers
30 views

How do I search WordPress posts by categories and tags in addition to title and content?

I would like to expand my site's default search fields (title and content) to include categories and tags without installing a plugin. Including the below code in functions.php allows me to ...
0
votes
1answer
23 views

problem with sql query

I have a problem with quotes with query. My code: $this->table_name= 'table_name'; $how_much = $this->wpdb->get_var($this->wpdb->prepare("SELECT COUNT(*) FROM {$this->...
0
votes
1answer
30 views

correct sql query

I wrote database queries some time ago and now I would like to improve them. But something I do wrong and i need help. class tags{ private $wpdb; public function __construct(){ ...
0
votes
0answers
18 views

Extended Custom Post type get all posts in wp-json

Using johnbillion/extended-cpts I try to figure out how can I have all posts in wp-json response. Till now what I tried did not worked I registered the post as it follows ...
0
votes
0answers
9 views

Problems logging on what does this mean [duplicate]

Warning: Declaration of thesis_comment::start_lvl(&$output, $depth, $args) should be compatible with Walker::start_lvl(&$output, $depth = 0, $args = Array) in /homepages/28/d429127183/htdocs/...
0
votes
0answers
20 views

Passing URL parameters to WordPress buttons

I'm beginner with programming and web development. I have a WordPress website (http://www.example.com). My post link is http://www.example.com/mypost/, so when I click on a button (assuming demo 1 ...
0
votes
1answer
19 views

SQL query, error

I have sql query but not work, i have notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE custom > ...
0
votes
0answers
45 views

SELECT max(meta_value) FROM wp_postmeta in current Category

I need to display the maximum price and minimum price of product From the current category I found this topic SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='price'... stops working ...
0
votes
1answer
116 views

add_query_arg not work in admin

I have code: class some{ public function run(){ add_filter('query_vars', array( $this, 'addPar')); $this->some_body(); } public function addPar($vars){ ...
0
votes
3answers
25 views

I have Wordpress setup on primary domain, how do I set it up on its subdomain using the same database?

I have a site www.domain.com with Wordpress installed. I need to create a subdomain for testing a new theme and have it linked to the main site's database. I have manually added the Wordpress files ...
0
votes
1answer
27 views

Query Post interferes with Pagination

Here is my situation, if you look at the following page: http://staging.cancerwellness.com/mind-body/cancerversary/, you will see that the pagination is not working. After researching the problem, I ...
0
votes
0answers
20 views

Sort custom post type by other custom post type field. (Places by their reviews mean vote)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average (mean) vote. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews ...
0
votes
0answers
22 views

Woocommerce in-stock only with product filter

I have a function that is pulling only in-stock items in Woocommerce. It's working properly but I need to be able to sort them alphabetically and then also have a dropdown filter so customers can ...
0
votes
1answer
27 views

SQL query to delete users with multiple meta keys and comments

I need help putting together an SQL that can delete users if they don't have (metakey1 or metakey2) and (does not have comments) I have this SQL which does it for single meta_key SELECT * FROM ...
1
vote
1answer
59 views

Get posts by category with pure SQL query

I have a meeting post type, whose titles automatically get set to a date of the form m/d/Y. I have the below query which gets all unique years from the post titles by selecting distinct values after ...
0
votes
1answer
27 views

Parse error: syntax error, unexpected '}' [closed]

<?php if(empty($username)) {array_push($errors, "Username is required")}; ?> i put this line inside a php file but there is a problem with it, can someone explain what I'm doing wrong?
0
votes
1answer
24 views

Query Posts | Combining multiple form inputs into query arguments to generate one filter result

I am trying and so far failing to take two form inputs and combine them into a single post query. I have tested these forms as two separate forms and both return results as expected, I am now trying ...
0
votes
1answer
27 views

My custom pagination not displaying

I'm testing a custom pagination feature but my pagination is not showing, is there something I forgot to do? here's my arguments and query inserted in my template: <?php ...
0
votes
1answer
31 views

Connecting to a different database

In my site I'd like to pull in data from another table, without having to create an API from the other site. I have seen that you can do something like this: $wpdbtest_otherdb = new wpdb('...
0
votes
1answer
40 views

SQL query to bulk change short code in all posts

PHP/SQL noob here. Based on this question I attempted to change some entries in phpmyadmin for my wordpress blog: I want to all galleries to link to file instead to file attachment (add link="file" to ...
0
votes
0answers
253 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
18 views

Why does a header location on admin_head remove the query var I'm setting in the location?

I have the following code which I thought would load the location with a query var of saved=1. public function __construct() { add_action( 'admin_head', array( $this, 'test' ) ); } public ...
0
votes
1answer
33 views

Strange results from WP_Query

I'm trying to retreive a set of custom posts using the following: // set search conditions $args = array( 'posts_per_page' => -1, 'post_type' => 'fee', 'meta_key' => 'fee_code', ...