Stack Exchange Network

Stack Exchange network consists of 174 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
0answers
9 views

Admin table Query filtering “WHERE” for custom post type

So I have been searching for a solution on how I can dynamically change a CPT admin table query by filter the result WHERE Status is equaled to some custom status. I have searched using function ...
4
votes
2answers
34 views

How to know if get_posts() failed?

So I see that get_posts() function return an array of posts. If there are posts, it returns an array of posts. If there are no posts it returns an empty array(). If there are posts, but the querying ...
0
votes
1answer
4 views

How to hide sub fields in a field group and also the entire field group if the answer selected is “no”

I have a field group (repeater field type) set up (titled "Units") with sub fields; sq footage, floor plans and availability (this is a yes/no selection). I have the availability sub field to display ...
0
votes
1answer
12 views

Restrict content based on user registration date

I’m looking for a way to restrict content displayed to subscribers based on when they registered. Basically, every week new content will be posted and I want to be able to restrict subscribers from ...
1
vote
1answer
18 views

Using $wpdb->update but confused on the WHERE in and SET

I'm confused on using the where in the $wpdb->update :/ These last few lines of my code are MEANT to update a table with an IP address when software is activated. If they change IPs it records the ...
0
votes
0answers
11 views

Can I replace the “Upgrade Network” with SQL query?

I have a WordPress Multisite network. When the WordPress version has been updated, I have to click on "Upgrade Network" for do same thing on all subsites. How can I replace this function with one SQL ...
0
votes
1answer
15 views

DELETE WooCommerce Order data from database

I spent some time in my DB trying to figure out how I can clean out some completed order data. Below is the query that I am confident will help remove the data from completed woocommerce orders. My ...
0
votes
1answer
16 views

How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page

Let's assume that the $wpdb->query() is properly escaped as needed, so there is no must for use of $wpdb->prepare(). However, some new requirements at Envato, not the w.org, requires to go over ...
0
votes
2answers
15 views

Is there a way to control both Order By and Order query parameters from one input field

I want to give the user the ability to order posts by post date/alphabetically either on ASC or DESC order through a select input on an archive page. The easy way would be to show two inputs on the ...
0
votes
1answer
11 views

Wp admin ajax load more

can someone explain to me how to include load more for archive, custom post type? I’ve been looking all over internet for a way to use it but can’t seem to find anything
0
votes
0answers
12 views

How to get_comments() ordered by date and parent?

So my starting point is: <?php $comments = get_comments(array( 'post_id' => $post->ID, 'status' => 'approve', 'type'=>'comment', '...
0
votes
2answers
19 views

WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category

I'm trying to do a single WP_Query to get the posts that are in 2 different custom post types but the second post type has to be from a specific taxonomy. This is what I'm currently doing: $...
0
votes
1answer
25 views

Is it possible to query from external database? [duplicate]

I have an extarnal database that I want to show some data in my wordpress site. What are the necessary steps to achieve this? edit: I changed config.inc.php according to https://stackoverflow.com/...
1
vote
0answers
26 views

Filter posts in category archive page by year using a dropdown

I'm trying to filter my posts by year in different categories by changing the query using a dropdown with this code: <form method="post" action=""> <...
1
vote
1answer
153 views

Order by summing multiple values

In a custom post type (products) I want to order products by summing multiple values based on user selection. I use custom taxonomies to filter the products. I could use the orderby meta_value but ...
0
votes
0answers
32 views

What is this Query? and why its taking too much time? Any way to optimize it?

Query: SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag') AND tt.count > 0 ORDER BY t.name ASC; Query_time: 3....
0
votes
1answer
24 views

I have two post types in the same query, how can I use CSS to select only one post type?

I'm using OceanWP theme and Elementor at this site: https://mymythos.org/ Ritual, Relaxation, and Motivation are examples of the second post type. Most of the other posts are normal WP posts.
0
votes
1answer
21 views

WordPress Database Query works in phpMyAdmin but not in the code

I have a simple SQL query: SELECT * FROM test_table__csv_import_temp_joblist WHERE url ='https://www.example.com' In phpMyAdmin, it works well and returns a result. In WP it returns nothing: $sql ...
1
vote
2answers
109 views

How to create a WP_Query to search the Title or Tag?

I have created a search using WP_Query, it seems like this query is looking for the queried term in title AND tags. Is there a way to have this search the title OR tags? $s = $request['s']; $tags = ...
0
votes
0answers
22 views

Set global $wp_query/$post variable for dynamic page generation

This is a difficult one to describe, but I'll do my best... I'm trying to set up pages that can be shown based on a second (meta/ACF) slug, dependent on the language the user is using. Essentially, I ...
0
votes
1answer
40 views

Plugin echos text from shortcode function in gutenberg page editor

I'm creating a plugin to load custom posts by custom taxonomy (restaurant menu plugin).. I'm calling the main function (holds everything) by the add_action hook on 'init' and inside it I have another ...
0
votes
2answers
21 views

How to give classname to post if post has no content?

I want to give a post a classname on the homepage (index) if the post on the single page has no content. So when the post itself exists but there is no content, I want to give a classname to that ...
0
votes
0answers
36 views

How to add variables to a template

I am using a query argument detail to check if a custom template should be loaded. This works fine, but I also need to add some variables that can be accessed from within the template. Here I am using ...
0
votes
1answer
12 views

How to exclude posts for current user

How can I hide posts that are in an array of ids in the usermeta for the current user in the main query. I can use post__not_in in meta_query but I do not know which option to use for only a specific ...
0
votes
0answers
18 views

Get count of each category depend on date - SQL query in WP

I would like to select all categories of my blog with count and date of create. I know that I have to convert post_date to specific month and then group my select by month(date) and category. However ...
0
votes
0answers
34 views

Query users by custom field

I want to get the users who registered within last 7 days, and meanwhile who have uploaded custom avatar. I've added a function allowing users to upload their own avatar img with a custom field ...
1
vote
1answer
29 views

Print terms with taxonomy and metabox value

I create metabox serial_language with ACP plugin into custom taxonomy name is serial. And I want to get only terms, in which custom field value is english, arabic. How to get only terms which have ...
0
votes
0answers
12 views

Having issue with dynamic data within restrict_manage_posts function

I have the dropdown dynamically populated with the titles of my podcast post type and I can successfully apply a filter by selected a podcast title and clicking filter. However, when the page loads ...
0
votes
1answer
18 views

I can't figure out what's wrong with this statement. $wpdb->query update

I'm trying to use the $wpdb-query method, but can't seem to get it to work. I get a 500 error when I try the following: $update_status = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}...
0
votes
1answer
42 views

How to display liked posts of current user in wordpress?

Im using an ajax like dislike post system on my wordpress theme. When the user likes the post there are some post metas to update or to add like the following: if( $post_like == "like" ){ ...
0
votes
1answer
30 views

how to SELECT for the current post id?

i am trying to get and count the values of a meta key (rating) and then calculate the sum. but the following code get all of values in wp_commentmeta table but i want to get just for the current post. ...
0
votes
1answer
16 views

Delete all drafts?

This is a common query to delete all post revisions: DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a....
1
vote
2answers
133 views

If newest post of category is newest post in general, skip first post of category

currently I am working on some customized blog templating and was wondering if there is any way to find out if the newest post of a category is also the newest post of the whole blog, so I can skip ...
0
votes
1answer
27 views

getting the values of hidden inputs to use them in a php mysql query

Im trying to update a value in the database, to do this I pass the values of the input an ID to another hidden inputs and submit the form via jquery, the values are set in the hidden input (tested). ...
0
votes
0answers
16 views

How to do a sql like query on serialized data of user meta data

As long I don't need to do a query with the data of all users, storing data like the zip code or city in the meta data as an serialized object works fine. But now I have to do a lot of different ...
0
votes
0answers
173 views

Offset with ajax load more posts duplicates

I have a shortcode that gets posts. I am using the shortcode three times on the page. The first time I grab the first 6 posts, the second time I offset by 6 and grab the next 4 posts, the third time I ...
0
votes
1answer
9 views

I need query_posts() to order results first by a meta value and then by post ID

I've read all the WordPress docs that seem relevant, and I've read lots of posts here and on other sites to find an answer to this, but I still can't find a way to do this. I have a custom post type. ...
1
vote
1answer
23 views

How to orderby multiple meta fields with another meta query

I have a custom post type ”events” with meta fields ”startdate” and ”enddate”. Archive query already uses meta query to show only upcoming or ongoing events, but in addition I need to order by both ...
0
votes
1answer
19 views

Nested select statements not working

I have 2 tables I need to search. 1st table Name: Personnel Fields: id, lname, fname, department, extension 2nd table Name: department Fields: id, department The 2nd table has the full department ...
1
vote
1answer
163 views

hook to get (and change) the search string before processing

I'm trying to intercept the search query before it's executed in Wordpress. I've tried a bunch of things but it's just not working. So, for example, a user enters the search term RED SHOES. I want ...
1
vote
2answers
70 views

Modals using loops and ACF [closed]

I am trying to make a page that queries every post of a specific category ("attractions"). I have been able to get the posts successfully, I just need to make the modals work. I have made a button ...
0
votes
1answer
69 views

WP_Query & Duplicate entries

I am currently using this code in order to get the latest three posts of my website, successfully and with no issues: $posts = get_posts( array( 'numberposts' => 3 ) ); but I want to switch to ...
0
votes
1answer
20 views

Shortcode to pull posts

I need some help please. I have created a shortcode to pull in posts, then using ajax it loads more posts. I have everything working but it is duplicating the first group of posts. below is my code. ...
0
votes
1answer
54 views

Any possible way to make $wpdb->get_results() return anything else than array?

So I'm using $wpdb->get_results() to query my database and then make AJAX call from JS file. The problem is that I need to get the value itself, like a string, instead of array, but as much as I ...
0
votes
0answers
18 views

My archives page won't sort posts by month

I'm trying to make my own theme and I've created an archive template that works fairly well. The template shows all posts, but the problem is that all posts will show if I go to /2018/11/ (posts were ...
0
votes
1answer
66 views

Pass array of taxonomy terms to wp_query

I am trying to compile an array of taxonomies and terms to pass to wp_query, my array looks like this... Array ( [0] => Array ( [taxonomy] => color [field] =&...
0
votes
1answer
36 views

How to export current year posts from Wordpress?

I have very big Wordpress database, in which I am storing the records from year(2013) and now I want to export only current year(2018) posts from the database and also want to import it into staging ...
0
votes
2answers
29 views

How to read the value of a WordPress $query associative array (hash) key

New to WordPress programming (coming from a more conventional environment) and trying to understand some of its "unique" qualities. There is a directory page on our website and this code resides, ...
0
votes
0answers
31 views

Is there any way to get all custom posts and all custom terms with it's meta in few queries?

I'm developing a website with a record for me query count. It has 720 Query for the main page. I want to reduce it. The main page structure is like this: ~10 Custom Taxonomy Term Each Term has a ...
0
votes
1answer
28 views

How to query 5 users in random who have published more than 10 posts

I want to display 5 users who have published more than 10 posts, when the page loaded again, it should show another 5 users or mixed with new users with more than 10 posts. How do I achieve this? ...