Questions tagged [query]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

Delete oldest wordpress post (SQL query)

I've reached the database limit on my hosting platform. I want to add a function to my functions.php that deletes the oldest post in my database anytime that I publish a new post. function ...
0
votes
1answer
29 views

Strange string in console from wpdb query

I use this code: $search = $this->wpdb->prepare("WHERE (name LIKE %s OR tag LIKE %s)", '%'. $this->wpdb->esc_like($word) .'%', '%'. $this->wpdb->esc_like($word) .'%'); and in ...
0
votes
0answers
16 views

Show post only for user that matches category

Disclaimer: I am not a developer. I know really a little code. Hey! Thank you for your time! Well, the situation is like this: I have posts that are set to "CategoryA" for example. In Elementor I ...
0
votes
0answers
7 views

Thickbox to display the result of a custom db query in admin

Is it possible to add php generated output in a Wordpress thickbox? I have the thickbox working fine from a button in a custom meta box, it displays html without issue. However, what I actually want ...
1
vote
1answer
21 views

How to check current user in meta value array in WP_Query meta_query

I am having trouble to query cpt for the current user if s/he is in the meta value array. query args $args = [ 'post_type' => $cp::get_module_cpt(), 'posts_per_page' => - 1, '...
0
votes
0answers
12 views

Get image with a sql query

I am working on a system outside Wordpress. This system is connected with the same database as my Wordpress. I made a small visual example of the tables below. wp_posts +----+----------------+-------...
0
votes
0answers
12 views

Display related posts based on matching the category and a tag within a custom taxonomy group

Hi community and thanks in advance. My aim, I simply want to display Pubs/Bars related by the same area tag, automatically, on every post. I found and followed what looked like an excellent solution ...
1
vote
0answers
9 views

Disable stored tags queries in admin page when posting a new post

First of all, I am sorry because I am a bit newbie here and I am still learning forgive me, please. I have a Wordpress website blog and I have a very big database of tags stored in MySQL the problem ...
0
votes
0answers
30 views

Modify query for different custom fields and search relations (AND / OR)

I try to modify a query for specific custom fields, with a different logic. I found the relevant part of the query, but can't change the relation (to AND) for a single custom field only. That's a bit ...
0
votes
0answers
14 views

Selecting specific query for offset

I'm trying to offset the first 3 posts in the functions.php from a query but the next affects all my queries in the homepage: add_action('pre_get_posts', 'myprefix_query_offset', 1 ); function ...
0
votes
1answer
33 views

Shortcode for custom query not returning results when attributes are added

I'm trying to build a shortcode that will allow the user to choose what category is displayed and how many posts will show. The shortcode worked fine until I added the 'tax_query' add_shortcode( '...
0
votes
0answers
5 views

Display different content depending on subdomain

I have a main website with the domain azerty.com, I have attached another subdomain which is uio.azerty.com. I'm looking for a solution that let me able to display different content on page depending ...
0
votes
1answer
14 views

Get posts that match defined arrays of tags

I've been scratching my head a lot and couldn't find a reasonable solution that would not require multiple queries. In my case, the posts have multiple tags, but they can be divided into to "sets" ...
0
votes
0answers
21 views

Related posts ordered by taxonomy

On my single post page, I display 4 related posts based on 3 custom taxonomies products, artists, and product-category. Everything works fine with the code below. BUT: Right now, with this code, the ...
0
votes
1answer
50 views

WordPress query: merge meta key (number) values and sort

There's a lot of great documentation on multiple column sorting using orderby however I can't seem to find a good WP_Query solution to this problem. Each post has two meta keys: rating_au and ...
0
votes
1answer
13 views

Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value

I have this query to do in my code: function get_item($id){ global $wpdb; $post_id_query = "SELECT * FROM wp_postmeta WHERE post_id = ". $id ." AND meta_key LIKE '%main%'"; $...
0
votes
0answers
9 views

Query for all the posts NOT in the current archive

For an archive showing Category B, I want to build a sidebar that shows all the posts that are NOT shown in the archive (Categories A, C, and D). This is for a general archive template, so I ...
0
votes
0answers
11 views

WordPress: SQL query to set TAG or CATEGORY if 1 or more words are written in post_title

SQL I need to set the TAG or CATEGORY in a post if there is a keyword in the post_title. Eg: IF "abc" word in post_title THEN set post TAG to "zzz" or IF "abc" word in post_title THEN set post ...
0
votes
1answer
14 views

Meta query and compare “!=” not working as expected

I realize that maybe this could be an already submitted question and I searched for it, but couldn't find it. I've got the following simple meta query: if (!is_admin() && ...
0
votes
0answers
22 views

How to sort posts by view count generated over last 7 days?

I want to display the most popular 7 posts by newly generated view counts over last 7 days, not the total view counts of a post. This is the code I'm using, however I can only sort results by total ...
0
votes
2answers
24 views

Displaying data from custom table

Just looking for a bit of advice on how to handle this: In the past (many moons ago) when I did the occasional php/mysql work, it was relatively easy to pull/display data from a table using the table ...
0
votes
1answer
16 views

SEO friendly query vars

I have an issue with a PHP form and the query vars it generates to fetch certain posts. An example of a generated URL could look like this: siteurl/properties/?state=georgia&type=industrial The ...
1
vote
1answer
53 views

Custom query for sidebar isn't returning results

I'm trying to create a shortcode that runs a custom query based on Yoast's primary category meta key. The goal is to pull posts with the same meta key value of the post being displayed and show 4 ...
1
vote
1answer
21 views

How do I see the mysql query generated by get_posts( $args )?

I'm trying to use get_posts( $args ) to get some custom post types. Is there a way to see the mysql query generated by the get_posts function?
0
votes
0answers
17 views

Heavy meta query causing SQL crash

I'm trying to search in two different post_type "places" and "events" but one parameter is about dates and places don't have this meta. Also, event got 4 different dates : a start_date and end_date ...
2
votes
1answer
50 views

Get image of latest post from taxonomies/categories

I have a custom post type "Artworks" with a custom taxonomy "Artists". I have a page where I list all the entries from the "Artists" taxonomy (Artist 1, Artist 2, Artist 3, etc.). How can I get the ...
1
vote
0answers
25 views

How to duplicate 5 posts out of WP_Query results?

If I have done a posts query which has fetched a long list of posts in to the WP_Object $all_posts, how, during the output loop, can I pull the next five posts of $all_posts in to new WP_Object $...
1
vote
2answers
20 views

Set WP_query 'order' option by another tables value

I created like system in wordpress. And I created 'sayim_beyenme' table and created 'say_post_id' and 'total_post_likes' datas. Now I want to display my posts orderby total likes per each post. I get ...
2
votes
0answers
32 views

How to output different posts per page?

I want to display one blog article less than on the following pages. The following code works but the the paginaton on the first page displays 1, 2, 3, 4 and on the next pages i get the correct ...
1
vote
1answer
56 views

How to display user order by role

I am trying to display user on query but i want to display order by user role. Suppose we have 2 user role, Gold and Free. I want to display Gold user first and then free users. $args = array( ...
1
vote
0answers
17 views

order one custom post type by modified time of another post type

i have post type name series and another name episodes in the homepage i show the series but rank them based on the one that has an episode added to it by time this is the original code which is ...
1
vote
0answers
13 views

Create a new query in function.php to filter blog posts

My goal is to filter blog posts (those which are requested in the blog page - Reading settings) depending on an expiration date, and then to change their category depending on a choosen future ...
0
votes
0answers
12 views

how to exclude specific pages form wordpress search results?

I want to show only today's events and the next events in Worpdress search results for every post with category "events". This is my code and it doesn't work, the events that have ended still appear ...
1
vote
0answers
13 views

I can 't display product images based on the label

The task is as follows. We have a product card template in Elementor, we have products with tags. The task is to use the Portfolio tool to display images of products that belong to the same label as ...
0
votes
1answer
29 views

Question about of query

I had a question that dont know why happen you use that query $parent_args = array( 'post_type' => $parent_post_type_slug, 'meta_key' => $child_post_field_key, '...
0
votes
0answers
8 views

when updating a page the query string getting removed from url and getting 502 error

For some reason, when updating the page in the WP admin, the query string the in the url is getting dropped off. for example: here is the page URL: https://www.sitenamehere.com/wp-admin/post.php?post=...
0
votes
0answers
26 views

Problems with using multiple conditional meta_query

I'm trying to use multiple meta_query for a custom search but one condition cause infinite loading. The results of the query will never display from the moment I add it. I do know that the conflict ...
0
votes
0answers
26 views

Specific SQL Query to filter certain WooCommerce products

I've written a script that generates a .PDF based on products in the WooCommerce store, the idea behind this is that a client can print it, fill it in and fax it to the company. This works all fine, ...
1
vote
0answers
50 views

Meta query for custom post type ignored in main query

I looked through the interwebz but couldn't find a solution. I am creating a website with custom post types where posts also include custom post meta (through ACF). I am creating an archive file and ...
0
votes
1answer
30 views

Prevent versioning for .woff (font) files

I'm trying to pass the preload check of Google PSI, so i've placed the local fonts i got, in the <head> as suggested using preload, as: <link rel="preload" as="font" href="myfont.woff" type="...
0
votes
0answers
24 views

Creating a custom WP query for a Custom Post Type

I'm trying to create a WP query to search a Custom post type by its title. By using the following code, I get all portfolio posts: $search_query = array( 'post_type' => 'portfolio', '...
0
votes
1answer
26 views

get_users with array as meta_value

My WordPress users have a custom birthday meta key (DD/MM/AAAA, e.g. 25/02/2020). If I want to get all users born today (25/02) I can use: $todays_birthday='25/02/'; get_users(array('meta_compare'=&...
0
votes
0answers
27 views

WordPress creating excessive joins on meta_query with search

I've a pre_get_posts filter with a check for main query and search, in this check I add a meta query: $meta_query = array( 'relation' => 'OR', array( 'key' => 'exclude', 'value' =&...
0
votes
0answers
16 views

Use ACF Relationship field to search against a subset of Posts

Using ACF I am able to present a list of Posts and allow the Editor to indicate related-content for a given Post. However, the editor has to search amongst all posts. Instead of having all possible ...
0
votes
1answer
51 views

Get 2 meta values from meta key column

I want to select 'name', 'SKU' and 'price' from 2 WP tables: wp_posts and wp_postmeta. I don't know how to get data from 'meta_value' column twice for 'meta_key'='_price' and 'meta_key'='_sku' , ex. ...
1
vote
1answer
13 views

How to paginate information obtained from a query to a custom table?

I am building a small application which consults a registration group of a bd in wordpress, the code is as follows. function opt_menu_cactaceas() { global $wpdb; $tabla_aspirantes = $wpdb->...
0
votes
0answers
12 views

WP_User_Query with multiple meta_query values not returning results

I want to return a query with the users that match 2 values of user metadata, this is the code I have, but returns the users without the filter, if i add in the relation "AND" instead of "OR" wont ...
-1
votes
1answer
20 views

Wordpress Admin Page Slow. Customer Post Type is the slowest

The admin page loads slowly ever since adding Custom Post types. I've added them using CPT UI and Custom Fields plugins in Wordpress. Whenever you click on the Custom post type from the sidebar it ...
1
vote
0answers
23 views

Weird orderby => post__in issue

I seem to have run into a sort of odd issue with WP_Query post__in I can't quite figure out. ANY help is appreciated! Goal/Progress so far: Overall I want to merge two arrays and use the merged ...
0
votes
0answers
16 views

Wp_Query in single custom post

I'm developing single layout page for a custom post type called 'chef'. The post title, content and all fields works well; I made some query in the loop successfully. Now I want to list the ...

1
2 3 4 5
35