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
0 answers
13 views

Use value from meta key array for use in WP_Query

I have a CPT named 'Physicians', and have assigned an ACF field named locations to that post type — locations is an ACF post object field. I also have a 'Locations' CPT and intend on displaying the ...
0 votes
0 answers
35 views

WP_Query sort by ACF date field (newest first) with blank dates first

I have a custom date field that is optional. If a date is not provided, the item should be first in the items returned by WP_Query. Example: 1st: entry with no date 2nd: entry with date 1 March 2023 ...
  • 109
0 votes
0 answers
34 views

Unexpected results custom wp_query and $the_query->request;

I have a problem with a WP query that I don't understand. If I query for the custom post type 'tribe_events' I get no results, while I know they exist. If I create a 'normal' sql query I do get the ...
  • 1
0 votes
0 answers
24 views

I'm trying to get posts under a custom taxonomy but I don't know what I'm doing wrong here

Im using the following php. and I'm only trying to call titles at the moment. I have 4 posts under this taxonomy. <?php $shopPosts = array( 'post_type' => array( ...
  • 1
0 votes
2 answers
60 views

WP Query - Can't get posts with specific taxonomy

I can't get my custom posts with a specific taxonomy. Here is my code in functions.php : function portalp_custom_post_type_realisations() { $labels = array( 'name' => ...
0 votes
0 answers
20 views

Query order by a numeric ACF field

I created a query for the custom post type of "departments" the query gets me every department with ACF field "type_of_cetifecate" = "bach" and with a certain category id,...
0 votes
0 answers
24 views

Simple Apex Charts with jQuery not working

I want to draw a chart in my Wordpress website usin Apexcharts by accessing a json file through a url. I've read the documentation and found the example in https://github.com/apexcharts/apexcharts.js/...
1 vote
1 answer
71 views

Custom query with custom filtering returning incorrect results

I've setup a custom query, I'm using Woocommerce and I am aware that it has it's own functionality, but have been tasked with creating custom filtering with a traditionally paged product/category ...
  • 59
0 votes
0 answers
17 views

How to sort search result by post_title, then by post_content

How to sort search result by post_title, then by post_content For example - if i search for word "Ball" i want to get results where "ball" exists in title, then the results where &...
0 votes
2 answers
33 views

How to include custom fields in wordpress search

As you know WordPress search only look at the post titles and contents, but I want the search to include also a custom field. Let me explain more: Consider a movie post with the title "Fast Five&...
0 votes
1 answer
22 views

Best performance for use Custom Field in WP

I started building a custom theme and I might need to have around 10 to 20 custom fields for posts and I need to 30 custom fields for theme options and image ads banner, and thinking if this will ...
0 votes
0 answers
81 views

Pagination only showed when no category is set in wp_query

tldr: On my production site only, when I set category_name to any category my pagination does not show up. Once I remove category_name from my wp_query the pagination shows up (for all posts on my ...
  • 135
0 votes
2 answers
55 views

WP_Query post_tilte search in posts table

Here is my array which I am trying to get "apple" keyword in post table but it can't work like I want. Please let me know what is wrong with my array? Array ( [paged] => 1 [...
1 vote
0 answers
59 views

Custom Taxonomy in custom REST API search

I am building my first theme where I use a custom search and I would like to include the ability to search by custom taxonomy. Currently, the taxonomy term shows up in Postman but no posts with that ...
1 vote
2 answers
35 views

How to use a conditional statement in a post loop but not count towards the "posts_per_page" if false

I have a WP_Query which has the "posts_per_page" parameter set to 12. I am then using a while loop to iterate over all of the posts and an IF statement to check whether a condition is true ...
  • 11
0 votes
0 answers
52 views

Extend search query to search meta keys values based on search string

I want to create an autocomplete AJAX search and I'm trying to have it where when the user starts typing, the list populates titles matching that search string. My issue is in the WP_query, because I ...
  • 353
0 votes
0 answers
45 views

How do I get parameters from the URL?

I have to be missing something obvious, but darn me into wool socks if I can figure out what it is. I have a set of news articles in the custom post type news. I'm trying to get an archive page ...
0 votes
1 answer
18 views

Dynamically count the number of custom post types associated to a custom taxonomy

I have two custom post types, "participants" and "reports". Both of them are associated with the custom taxonomy "year". So in the post "report 1" that is ...
0 votes
1 answer
26 views

AJAX WP_Query's order and orderby parameters not working

TL;DR SUMMARY OF PROBLEM AJAX will not use the proper order and orderby parameters given, and instead sorts post by menu_order (posts section doesn't even have post attributes set as true). PROBLEM ...
0 votes
0 answers
34 views

AJAX multiple search boxes not merging with array merge

this is a very frustrating problem. I have some search boxes for different feilds on my site. some are acf meta fields, another is for title, and another for a keyword taxonomy. But on the front end, ...
0 votes
0 answers
27 views

Display Featured image from custom post type category (custom taxonomy) wise

I am creating a dynamic slider. I have set slider images in featured image. I want featured images according to category wise. Please help me with this. Thank you. <?php $cottage = new WP_Query( ...
0 votes
2 answers
47 views

How to put posts with some taxonomy on top of others in `pre_get_posts`

The following tax_query returns only matched posts (with 'matchedstring' IN taxonomy array): function only_returns_matched_posts( $query ) { if( !$query->is_main_query() || is_admin() ) ...
  • 101
0 votes
1 answer
33 views

WP_query shortcode inside acf Repeater breaks the repeater loop

I have a shortcode that lists CPTs and works great everywhere but if I use the shortcode in an ACF repeater the reapeater stops repeating right after the shortcode. I tried reseting postdata in ...
0 votes
0 answers
29 views

taxonomy-{term}.php terms pagination returning 404 after a certain page

So my taxonomy-movies.php terms pagination returns 404 after a certain page, I've been sitting on this for like 3 days and still can't get answers from related question... So to give you guys some ...
0 votes
1 answer
27 views

after refresh the id that shows correct in first time click, changes to 1

I made a like post type for another post type called recipe that user can toggle for like and getting back the like. I have to get the latest like id of specific single recipe when cliked on in data-...
  • 3
0 votes
1 answer
26 views

How do I exclude the current post from the upcoming post query

Summary: I have a page template with 3 queries. Current Exhibition Upcoming Exhibition Past Exhibition The dates are custom fields. The problem I'm having is, how do I dynamically exclude the ...
0 votes
1 answer
20 views

loop hierarchical custom post type, child pages only

I need to query all pages of a custom post type that are children, not just children of a specific page. different way to say it is exclude all parent pages from a query of a custom post type. never ...
0 votes
1 answer
18 views

Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2

$args = array( 'post_type' => 'product', 'meta_key' => 'sorting_weight', 'orderby' => 'meta_value_num', 'posts_per_page' => -1, 'order' => 'DESC', 'tax_query' =&...
4 votes
1 answer
83 views

Get related posts matching most of the provided tags using WP_Query

I need help in getting related posts using multiple tags. I have posts with the tags poetry, motivational, attitude, rules, lines, sigma and inspirations. I want related posts matching most of these ...
  • 43
0 votes
0 answers
17 views

Prevent URL Parameter Affecting other WP Query

I have a loop the generates a list of custom post types as a menu: $loop = new WP_Query( array( 'post_type' => 'farm-shop', 'orderby' => 'menu_order', ) ); The menu ...
1 vote
1 answer
22 views

Complex Custom Loop with Includes

The Problem I have a complex loop designed for showcasing my portfolio. Here is the criteria: Portfolio is powered by a custom post type called PORTFOLIO Each post will be assigned a class of either '...
0 votes
0 answers
14 views

How to save the results of a query as a php file for an autocomplete search bar

I'm looking to cache the results of some queries in order to make autocomplete search bars and lists for forms. I'm using it for a form with <input type="list">. I'd like to save the ...
0 votes
1 answer
21 views

Load posts via AJAX without draft status

When I load posts in the frontend via AJAX, I also see posts that have the status "Draft": function get_projects() { $args = array("post_type" => "project"); $...
  • 159
1 vote
1 answer
39 views

Limit paginated result set to a maximum number of posts

I would like to create a paginated result using a maximum number of posts. I have been trying to achieve this using \WP_Query class e.g: function getQuery(int $page, int $posts_per_page = 2, int $...
  • 1,094
1 vote
0 answers
17 views

on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query

Current behavior I have a media page that uses a custom WP_Query to return all thumbnails of media library attachments (regardless of post parent) with a custom taxonomy of media_visibility that has ...
  • 208
4 votes
1 answer
58 views

Can I use WP_Query to find a post with a particular menu_order?

I can use WP_Query to order posts matching my query by menu_order. But can I also specifically find posts that have a particular menu_order? Even better, can I find posts with a menu_order larger than ...
  • 219
0 votes
0 answers
36 views

WP_Query (or WC_Product_Query) out of memory

I'm building a plugin that's supposed to show the user a list of all products on the site. This testing website has 25000 products on purpose in order to test performance. This server and Wordpress ...
  • 96
1 vote
0 answers
18 views

WordPress Ajax search filter on dropdown select

I am trying to create search filter on click dropdown selection, but still not achieved, here is my code. Here is form code, which contains three different dropdwon <form id="filter-form"&...
0 votes
0 answers
15 views

Search results stuck on page 1

The problem statement For some reason when the user does a search the results page (search.php) only show the first page results. The pagination (next and previous links) also believes its on page 1. ...
0 votes
0 answers
27 views

AJAX search function resets wp_query vars

I have a custom post type called event. On the archive page I implemented a simple search which returns a selection of posts. Before submitting the search form I'm seeing the proper query vars for the ...
  • 75
0 votes
0 answers
26 views

I need to get all categories from a WP_Query

Actualy i'm doing this $loop = new WP_Query($args); while ($loop->have_posts()) : $ID = $postData->ID; $freeCategories = get_terms(array( 'taxonomy' => "product_cat"...
0 votes
1 answer
17 views

Group By query based on Custom Field

Hello I have a field name team and I would like to get the total amount that each team has been gatthered Im trying to echo the team name and total amount and group it by team but it doesn't work. ...
  • 13
0 votes
1 answer
36 views

How to sort custom sortable column by custom table value

I have a custom table with data in it that I am showing in a column. I would like to make this column sortable. Lets say that the custom table has three values for the sake of simplicity. row_id, ...
0 votes
1 answer
34 views

filter on get_posts efficiently

I have posts with the following categories: A category that is a year(2017,2018...2022), a category that is type:(worldwide,Europe, local) I am trying to give users in the frontend advanced search ...
1 vote
0 answers
17 views

Query custom post type and group by taxonomy

I struggle a bit with my piece of code - it's main goal is to show list of custom post type (called "career") childs grouped by custom taxonomy. How it should work? A user see default list ...
0 votes
1 answer
16 views

Why does wp_query only display the most recent post when using order ASC?

Problem: I want to list posts of a category, displaying those with custom-field 'start-date' after today (in the future) with order ASC. When this is done, I want to display all those with start-date ...
  • 25
0 votes
0 answers
20 views

Bulk delete comments, foreach loop

I have a question about WordPress's wp_delete_comment() function. Let's assume I have an array that contains more than 3000 comments ID in it and I wanna remove all of them. First approuch would be ...
0 votes
1 answer
30 views

Count custom posts type and filter by tag

I'm using this code to count the number of posts of a specific custom post type that have also a specific tag: <?php //Array $args = array( 'post_type' => 'cars', '...
3 votes
1 answer
55 views

How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?

I have the following SQL query: SELECT t.name FROM wp_posts p INNER JOIN wp_term_relationships tr ON tr.object_id = p.id INNER JOIN wp_terms t ON tr.term_taxonomy_id = t.term_id WHERE p.id ...
  • 181
1 vote
1 answer
51 views

Filters do not work when there are multiple (one works)

I have this functions code: function my_query($query) { if (is_post_type_archive('mycustomposttype')) { $orderby = sanitize_text_field(get_query_var('orderby')); $orderby2 = ...
  • 299

1
2 3 4 5
114