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
14 views

Array to string conversion on array_map

I'm using array_map to sort out an array with all of my _octopud_id's. var_dump($offices): Returns the following: array (size=500) 0 => array (size=1) 'id' => string '1382' (...
0
votes
1answer
17 views

Get number of authors

I want to get the number of authors. I saw this and moved (all). I got number 0 or 1 but real is 3. What should I do?
0
votes
1answer
14 views

Store metakey value as an array

How could one grab the post meta key of _octopus_id and store that as an array. Here is what I'm trying to achieve: Call the WP_Query and pull all the offices with _octopus_id Use the value of ...
0
votes
0answers
28 views

INNER JOIN custom tables - SQL Query

H, I am trying to get results from two tables with INNER JOIN in WordPress theme template file, but I don't know what's I am doing wrong. Please help me, here is the code below global $wpdb; $user_id ...
0
votes
1answer
13 views

Using Transients

I am new to the transient concept. But I am not sure about the efficient method to use it. I really liked it as it removed the duplicate queries that I had. I have set set_transient( '...
-1
votes
1answer
21 views

how to use transient method?

It was suggested to use a transient method to remove the duplicate queries Duplicate Queries Why does this don't work? Is it the wrong way to use it private function get_acf_list() { if(!...
0
votes
0answers
12 views

whether a nonce is required for get type and get_query_var?

I have a front form that allows filtering. I think I need a nonce but I am not sure to use it or not. I use the get_query_var method to modify the main query. It uses a get method. whether a nonce is ...
0
votes
1answer
17 views

Increment paged on WP_Query

What's the proper way to increment 'paged' under a WP_Query call? This is what I have below: $custom_query = new WP_Query([ 'post_type' => 'employee', 'post_status' => 'any',...
0
votes
1answer
10 views

Target post_date_gmt if it's empty or not set

So I'm trying to target some posts to include in my function but I just can't seem to get it to work. When I have the meta_query taken out I get 9 results (Works): $args = array( 'post_type' ...
0
votes
0answers
15 views

WP_Query Order by meta_key menu_order?

I have a custom post type called Team. This consists of people. Each person is linked to a taxonomy called Team. I want a WP_Query which displays the results by the taxonomy menu order and then ...
-1
votes
1answer
19 views

How to alter query so that image changes in order every time page is refreshed

I'm trying to figure out which is best way to alter query so that image changes every time page is refreshed. The query is ordered by rand at the moment and the code looks like this: $settings=...
0
votes
0answers
41 views

searching for posts, with user meta parameters

I try to show posts for all registered users. The users have some user_meta fields, that i can display suggested posts for them. I have exact the same function in use on the profile page of a user, ...
0
votes
0answers
7 views

WP_Query paginate with one term per page?

We have a site with an online newsletter/magazine using a custom post type (newsletter). What we're trying to do is display the articles by 'Issue' (a custom taxonomy called 'issue'), so that all of ...
0
votes
1answer
20 views

SELECT TOP 1 in wp_query for each groupby meta value

Is there any way using wp_query class to execute SELECT TOP 1 sql command while using groupby for each meta_value results. I need the wp_query to select only the first one of each groupby meta_value ...
0
votes
0answers
30 views

Meta query orderby meta_value_num sorting by role first

I want all of the results to order by meta_value_num, but it's ordering by role first. How do I get them to ignore the role order? Here's my code: $user_query = new WP_User_Query( array( '...
0
votes
0answers
20 views

WP_User_Query Orderby Not Working

If I use the following code, I can retrieve users in the correct order: $user_query = new WP_User_Query( array( 'role__in' => wp_parse_list( $atts['userrole'] ), 'meta_query' => ...
0
votes
1answer
22 views

Get unique post by meta value using wp_query

I use wp_query to retrieve my posts by using a meta value. One of the meta values have the same text stored in the database. Let me give an example. Post title Meta value hello1 text1 hello2 ...
0
votes
0answers
12 views

post_per_page and multiple categories

I need some tips for the code, I need to get 5 posts per every category, but this is show 5 post at all.. <div id="projects-carousel" class="owl-carousel"> <?php $query = new WP_Query( array(...
0
votes
0answers
23 views

Loop through an iteration of 500 results at a time and increment page and restart with next 500

Below, I will explain all the steps and how everything works so you get a better understanding of what I'm trying to achieve. The import_employees function kicks off and grabs the $settings['page'] = ...
-1
votes
1answer
30 views

Pagination is not working using WP_Query

I have coded for custom post type pagination but it doesn't work. Here is some code for it. <?php global $wpdb; $userid = get_current_user_id(); $userData = get_user_meta($userid , 'referat', true)...
0
votes
0answers
19 views

Custom post type category returns null

I created a CPT with CPT UI and register a taxonomy for my CPT. I get all of this post type <?php $args = array( 'post_type' => 'market', 'post_status' => 'publish', 'posts_per_page' =&...
0
votes
2answers
21 views

2 column recent post query not respecting float right

I am trying to display recent posts where I have one on the left showing the image, title, excerpt and author info and on the right, just the title, date and author information. I want it to show the ...
0
votes
1answer
23 views

Check the database for a postmeta field

So I'm trying to use the metadata exists call to check the WordPress database and see if some metadata exists. For some reason, I don't think if the metadata_exists call is the correct one in this ...
1
vote
1answer
31 views

Duplicate Queries

While using the query monitor plugin I could notice I am making a database query 4 times. I am using OPP. So I have a method that gets me a list of posts by querying the database. I have to do this 4 ...
1
vote
0answers
13 views

How to do WP_Query with two meta fields with orderby clause

The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is the query I did so far, but its not working. $args = array( 'post_type' =&...
0
votes
0answers
33 views

Nested taxonomy handling on wp_query

I am using wp_query to show specific posts to users. I need to filter the posts by 2 arguments ( $artist AND $region_con ). $artist is a single value and is easy to implement in the nested handling. $...
0
votes
1answer
41 views

Should I reset $wp_query?

I am not totally new on WordPress but the query thing is a bit confusing to me. I searched the web and read a lot of articles, but I couldn't find what I needed. Maybe it could help a lot of people ...
-1
votes
0answers
11 views

How do you query custom post types with the same category name as the post title?

How do you query custom post types belonging to a category with the same name as the default post title of the post where the post types are displayed?
0
votes
2answers
18 views

exclude posts with a specific custom field and value

How can I exclude posts with a specific custom field and value with this query? $my_query = new WP_Query( $args = array( // It should be in the first category of our post: '...
0
votes
1answer
11 views

Performance considerations - postmeta table versus new table for custom posts with foreign keys?

I am modifying a plugin that uses various custom posts types. The types are courses lessons topics At course, lesson, or topic level there can also be quizzes and assignments. ALso the ...
0
votes
0answers
20 views

Why does my output of get_the_ID() change after a wp_query?

I use ACF. I have the following code: $args = array( "post_type" => "membership", "posts_per_page" => 1, 'meta_query' => array( 'relation' => '...
0
votes
0answers
17 views

Static position inside an ajax-called loop

0 I am serving an output of five posts in my homepage and upon scroll down, I use an Ajax call to implement a load-more functionality, which loads a next series of 5 posts. So, upon scroll down, $...
0
votes
0answers
17 views

Sort on multiple custom fields using wp_query not working

I've been googling this for a couple days, and have read several similar questions on this site, but still can't figure out what I'm doing wrong. I'm brand-new (like two weeks) to customizing ...
0
votes
0answers
83 views

Input check to custom post type query

I have a series of inputs with the custom post ID as the value. When I write the query manually with specific ID's it works fine and the right custom posts appear. However, when I've been trying to ...
0
votes
1answer
16 views

How can I re-query post_type and rewrite the url?

I have the url slush like the below. /category/land-residential-farm/?property_com_listing_type=sale I want to write the url to /category/land-residential-farm/property-for-sale then re-query the ...
1
vote
0answers
20 views

WP Query using tax_query & meta_query

I have a custom post type called events. I have a custom taxonomy called issueEvent. I have several ACF fields on the taxonomy. The one I have to query by is a checkbox. I want to query 3 specific ...
1
vote
1answer
25 views

WP_Query with Metavalue

I have developed this function but returns 0 results. I think there is a problem with the way I am passing the meta_value arguments. Any help? add_shortcode( 'sc_count_brands', 'sc_count_brands_code' ...
0
votes
0answers
12 views

Using meta data to retrieve related posts - a way to use nested relations?

I am modifying a site that currently has various custom post types. The structure of one to many relationships is basically course lesson lesson topic lesson quiz topic quiz There ...
0
votes
2answers
18 views

Update wp_query every week

What I'm trying to achieve: my homepage displays 3 random posts from each of 5 different categories. That part is easy. What's a little unique and I can't quite figure out how to accomplish, I would ...
0
votes
0answers
14 views

Custom queries and wp_reset_postdata();

I am trying to understand how the loop works when you are using custom query and the use of wp_reset_postdata(); WP says It is necessary to reset the main loop data after a nested loop so that ...
0
votes
0answers
48 views

wp_post_delete is deleting all offices

Below, I will supply the code that I am using right now to distinguish between my offices: function import_offices() { $log = []; $name = 'octopus_import_offices'; $settings = ...
0
votes
1answer
58 views

Why can my filter query SOME metadata but not other metadata?

I'm stumped by what seems like a simple task: I want to randomly select a post that fits certain criteria (metadata set by a specific plugin) and then return that random post to the plugin in question....
0
votes
0answers
28 views

Display specific posts based on an ID of another post

I'm trying to display specific posts based on an ID of a post. I got it working with 2 posts and I will get it working for the 10 posts that I need it for, but it's going to be a lot of code and I ...
-1
votes
1answer
23 views

Displaying specific posts from query thumbnail outside div

I'm trying to display thumbnails inside a div from a query, but the thumbnail is outside the div and I don't know what I'm doing wrong, here is my code: <?php // WP_Query arguments $args = array( ...
0
votes
1answer
36 views

Avoid removing duplicate posts

I have an arrays of IDs which may contain duplicate values. Array ( [0] => 24 [1] => 11 [2] => 60 [3] => 11 ) I'd like to loop through those IDs using WP Query and the ...
1
vote
1answer
17 views

difference between like '%%%var%%' and '%var%'

What is the difference (if any) between: $ids = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_product_attributes' AND meta_value LIKE '%%%s%%';", $code))...
0
votes
0answers
9 views

Sort query by title in meta value stored as id

How can I sort a query alphabetically by meta value where the meta value has the id of a related post and not its title? I have two custom post types: news and companies. Each post under news has a ...
0
votes
0answers
16 views

how to display wordpress post which is published in past 5/10/20/30/60 minutes & 1/5/12/24 hours slabe?

I want the page to show a list of published news in a particular time frame. Please take a look example :- Here is my code which i am using : <?php ...
0
votes
1answer
29 views

Running multiple WP_Query

I'm trying to run multiple wp_queries in my main homepage .. is this a good practice ? $argsPort= array( 'posts_per_page' => 6, 'category_name' => 'portefolio', '...
0
votes
0answers
7 views

How can I create a left join with posts that are associated with a post_tag?

How can I create a left join with posts that are associated with a post_tag? Example: cpt1: ID Course term_id 1 Course1 100 2 Course2 100 3 Course3 cpt2: ID User term_id 10 User1 100 11 User2 ...