Questions tagged [wp-query]

"wp-query" ambiguously refers to one of two things. 1) WP_Query is a class native to WordPress which allows users to query the posts database using a number of criteria. 2) $wp_query is the global variable that holds the main query object prepared by WordPress based on a given request.

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

Populate select list with meta values from all posts of a Custom Post Type

I've got a CPT of Inventory and I'm trying to show a dropdown of all Mfrs. I've got the form and pre_get_posts function so that when a user selects a Mfr, the page refreshes and shows only the ...
1
vote
0answers
27 views

DROP TABLE with uninstall hook not working

I wanted to explore more options and thats the reason for me building my first WP Plugin. I tryed to follow the coding standards, but I am struggeling hard right now. I am trying to drop my created ...
0
votes
0answers
8 views

How can I display a category page with future sub categories?

In a recent project I had to build a custom category page. On this parent category, I display sub categories.(just thumbnail and title) Some of these subcategories'posts will be published in future. ...
0
votes
0answers
5 views

Query post by one taxonomy and sort by another

I am getting the posts by a custom taxonomy called "wall_of_fame". This gets me all the posts that match "Yes" in this custom taxonomy. $query_args = array( 'post_type' => '...
0
votes
1answer
26 views

How can I style future post?

I'm showing published and future posts on a category page. I need to make future posts unclickable and add a special class to them in order to add a gray overlay, meaning the post is upcoming.. trying ...
0
votes
1answer
11 views

Display post count for a specific month

I am trying to display post count for a specific month, But something is wrong with my query because count is wrong. here I want to get post count for Aprel month. Can anyone help me please ? Thanks ...
0
votes
0answers
10 views

Prioritize search result to show matching exact result

Suppose I search "TA" on wordpress query, the results show the posts with words containing "TA" first, like sTAnd, I want to display exact word "TA" first then words ...
0
votes
0answers
8 views

How to show CPTs in term archive

I attached default taxonomy "category" to a "story" custom post type, when I register it: 'show_in_rest' => true, 'show_in_feed' => true, 'taxonomies' => ['...
0
votes
0answers
9 views

Order By Custom Field, otherwise by Date?

I have two CPT and want to order them with Events first, then Articles. Events should be ordered ASC by wpcf-date_time - the event's date, which is in the future. The Articles should be ordered by ...
0
votes
1answer
16 views

pre_get_posts pagination not working

I've been trying to fix my pagination on for category pages but am at a loss. This is my pre_get_posts function for category pages. add_action( 'pre_get_posts', function ( $q ) { if ( !is_admin() /...
0
votes
0answers
5 views

Any way to autogenerate a custom post with next 7 days of another custom post type in wp admin?

Currently, I have a custom post type of Event which uses WP_Query to get the next 7 days of events and places them into a carousel on the homepage. I am looking to further the functionality but ...
0
votes
1answer
10 views

Does WordPress have something like Drupal's DB API?

That is, the ability to write database queries like: $query = db_select('users', 'u'); $query->condition('u.uid', 0, '<>'); $query->execute(); I'm converting a Drupal site to WordPress, ...
0
votes
1answer
29 views

Shortcode Not Working in Slider When Added To Post Title

I've coded a shortcode to add manually to specific post title fields so i can style part of a title add_shortcode( 'green', 'green_shortcode' ); function green_shortcode( $atts, $content = 0 ) { $...
0
votes
0answers
28 views

Prevent Duplicate Post Counted by Query

<?php while ( have_posts() ) : the_post(); $get_series_id = get_post_meta( get_the_ID(), 'series_seri', true ); if (in_array($get_series_id, $do_not_duplicate)) { ...
0
votes
0answers
19 views

How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?

The Setup I have divided my blog into 3 categories with their respective slugs. There are 3 pages corresponding to these 3 categories with their respective custom page templates. On each page, I ...
0
votes
0answers
6 views

How to query results for post_title and Custom Post Type/ACF field pivot query

I have a custom query that needs to match a search term to a custom post type of event by post title and by an ACF field host and then filters out events that have passed the current date to a REST ...
0
votes
0answers
12 views

get_the_excerpt doesn't work with default items but works with my customs post types

the excerpt function not work in my custom post template using Wordpress default posts in the query loop, but they work fine with custom post type. I enabled the display of excerpt by checking the &...
0
votes
0answers
24 views

meta_query not behaving well with spaces

I have created a custom search page where i can search in a Custom Post Type (Products) based on a number of custom fields that each product post has. This is the search input: <form role="...
0
votes
0answers
12 views

Taxonomy list inside the query

Is it possible to get a list of the "terms of taxonomy" or "just used taxonomy types" defined within that archive without looking at all pages of an archive query in a loop? What I ...
0
votes
0answers
14 views

What are these TONS of queries on WP homepage?

On my WP install I have a ton of DB queries. Just loading a random page averages 2250 DB queries like these (according to Query Monitor): SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE ...
0
votes
1answer
23 views

WP_Query: how to search tags in addition to a custom post type?

Below is what I have so far for a custom rest endpoint ('placesdb/v1/search?term=') for a custom post type (place). This successfully returns all the places that have the search term in the title or ...
1
vote
1answer
52 views

Filter wp_query to search post title in function

I'm making a query to pull posts from my post query based on a user entry in a form. I want to keep the form simple so I'm hoping to only have to use one field. That field would say search part ...
0
votes
0answers
7 views

Custom woocommerce product table shortcode [closed]

I am trying to write some custom code that goes in the functions.php file to create a shortcode that will display a list of products in a chosen category. Everything seems to work but there is a ...
0
votes
0answers
13 views

How to Ignore Specific/Common Words in Wordpress Search Query?

I am facing a strange problem with the search engine of my WordPress website. I want to turn off the case sensitivity of my WordPress search engine. For example if a user search "apple of one's ...
1
vote
0answers
14 views

Getting post revision and printing them on the post content site

I trying to print older post revisions on the content.php site (theme: twentytwenty), and this, with staticly set value works.. $query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts ...
0
votes
1answer
10 views

display post count in archive page that have relation with another taxonomy term

This topic has been ask in Stackexchange many times. But most of question unanswered or has incomplete answer. My custom post type "Product" and two different taxonomy "Sectors" ...
0
votes
2answers
36 views

How can I sort the results of a REST API response by the title of a connected custom post type?

I'm using the rest_photo_query filter to manipulate the arguments of WP_Query through the use of my own GET parameters. It's working perfectly and fast, with one exception. I can adjust the orderby ...
0
votes
0answers
18 views

get_user_meta orderby meta_value

I have the following situation: Each time a specific action is fired, a custom-id + timestamp for that user is saved in the wp_usermeta. With get_user_meta i can output and sort the data visually ...
0
votes
0answers
31 views

tax_query not working on custom post type

For some reason my tax_query is returning 0 posts. I'm able to assign posts to the Tax and the archive pages work correctly. When I try to create the below custom query the post_count in the ...
0
votes
0answers
15 views

Query Attributes optional argument

I am using this code which currently the user calls as: [myimg no="1"] , [myimg no="2"] etc.. function myimg_shortcode($atts){ $atts = shortcode_atts( array('no' => 1,), $atts )...
0
votes
1answer
14 views

Filter for each loop when WP_Query has no posts to show

I'm looking for a way to filter the results of a for each loop based on a custom taxonomy when the WP_Query inside the for each loop has no results. More specific, I have an Event post type with a ...
0
votes
1answer
14 views

Save queried result into database

in multi author website when author publish post , he/her can give star rating to his/her own post. and I can display average rating for every taxonomy term using this formula: AVERAGE RATING=TOTAL ...
0
votes
0answers
17 views

Confused. How to remove WP_Query $args from AJAX posts loop and make it work?

I am currently working on a custom theme project where I am trying to make AJAX load more function work for custom-post-type, 'product' I just made. I went through a tutorial on internet and got the ...
0
votes
1answer
12 views

Show child by slug, while knowing parent ID

Im trying this to show My CurrentPage (Licenciatura en Ciencias del Arte y Gestión Cultural.) child called "Infraestructura" by it's slug. I don't know whats wrong with my code. It Returns ...
0
votes
0answers
10 views

Show products from the same sub category

I'm trying to write a wp_query in my template of a woocommerce product to display a carousel of some related products from the same sub category of the product I'm seeing. My code is like this <...
1
vote
0answers
19 views

How to orderby multiple meta fields if some fields are empty

I'm trying to orderby meta fields value, but sometimes those values are empty : A > title = 'The apartment', wpcf-f-french-operating-title = ' ', wpcf-f-order-title = 'Apartment' B > title = '...
1
vote
2answers
33 views

Formulate a url to show posts with both taxonomy terms

I would like to show an archive of posts that have two taxonomy terms in common. So for example, I'd like to show all posts that have both the terms "sauce" and "cheese" in the ...
1
vote
1answer
17 views

How can I make WP_Query get posts that have a tag but also have random other tags?

I am trying to make the category page on my Wordpress website. To position some of my content, I use post tags. To get the post that goes in a specific spot on my page, I make a WP_Query with $args ...
0
votes
1answer
24 views

Combine 2 WP_queries into one (OR relation)

I have 2 WP_queries that I want to combine into 1 query. These are my orginal 2 queries: $childlist = new WP_Query( array ( 'numberposts' => -1, 'post_type' => 'page', '...
0
votes
1answer
18 views

How can i share WP_Query between multiple functions?

I have 2 functions that use the same $args for the WP_Query class. How can i make it so I have to define the WP_Query class only once, and share all the returns, i.e. I should be able to loop through ...
0
votes
0answers
17 views

Slow website when i use duplicate meta_key with different compare

The following code is exactly what I need to load the posts that interest me, but the website takes about 8 seconds to load when I run it. If I stop using 'relation' => 'OR' the website loads ...
0
votes
1answer
18 views

WP_Query for Attachments not working as expected

I have a function to retrieve a random set of pictures according to the category. This has been working when I set up the website last year. Now I tested the site today and found out that none of my ...
0
votes
1answer
13 views

Query to Exclude Child Pages from Custom Post Type Archive

I have a hierarchical custom post type called "Services". On the Services archive page I want to display only parent Services and exclude child Services. I found similar answers to my ...
0
votes
0answers
25 views

WP_Query get always custom post_type for first

This is my problem. In a WP_Query I want to get always a content of particular post_type like first occurance in a list of five. This is the code I use: $args = [ 'post_type' => ...
1
vote
0answers
15 views

Editing the default wordpress search

My wordpress sites search function is not relaxed enough for my liking. I want it to match more items and be less strict. How would i do this? I was thinking it would to do a pre-get posts filter but ...
1
vote
1answer
20 views

Query custom post type by category slug

I'm trying to query a custom post type by its category slug, but its not working at all my custom post type definitions: add_action( 'init', 'custom_post_albuns' ); // The custom function to ...
1
vote
1answer
10 views

How can I get the number of custom post type posts that have a specific attachment image set?

I'm currently using this to filter out only posts that have a specific custom image attachment field value. But it's returning 0. I used this method for other custom fields and it worked great. Is ...
1
vote
0answers
17 views

Wordpress multisite - fallback on subsites to main site on 404 and dealing with switch_to_blog function

Main topic: I have installation of wordpress using bedrock and multisite. I want my subsites to have fallback when page doesn't exist on them and display content of existing page Example scenario: ...
1
vote
0answers
8 views

Hiding Draft Post In Admin

Does anyone know of a way to hide draft post so that when "All" post is selected, draft post is not included? I tried adding this code to my functions.php file but it lead to an error, I'm ...
0
votes
0answers
13 views

OrderBY meta_key_value including null value

I am trying to do a simple query in wordpress ordered by a meta_value_num of a custom field, the problem is that not all the inputs have a value so it gives me a null value and it does not show very ...

1
2 3 4 5
107