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
3answers
3k views

Setting standard hover box size

I want to set up a grid of hover boxes. I have set up three columns so they are all the same width, but I want to set the size so that they are the same depth regardless of how much text is in there (...
3
votes
1answer
459 views

Query Custom Meta Value with Increment

I have a Query searching for a meta value I have added to my posts (meta-select). I have it feeding out in a loop with 4 results. Let's say I want this loop to start with the meta value "2" and work ...
0
votes
1answer
526 views

Unable to get all tags from specific categories

Page in question. I'm trying to use a WP_Query(); targeting specific categories and displaying all the tags used for posts within those categories. I noticed that some tags, like truffles aren't ...
0
votes
3answers
518 views

Carousel Loop only duplicating

I have problem with looping and WP_Query. Any idea how i can implement the multiple carouselitems please check what html output should be in html So basically one of my goal is each div have a pages ...
1
vote
1answer
23 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
45 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

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 ...
-1
votes
1answer
29 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
38 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
15 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( '...
0
votes
0answers
18 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
671 views

Query string order by custom field

I have code for custom post type, for custom taxonomy for displaying category posts. I am using Advanced Custom Fields What I want is to order posts by custom field value, and I was wondering how I ...
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',...
1
vote
1answer
457 views

Current post in AJAX call is always zero

I have a custom post type named event and a button to load more timeline. I need to arange current timeline item to the left or right depending on his current_post from WP_query object. Ex: if (...
0
votes
1answer
12 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
25 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
vote
2answers
2k views

How to get post from all Blog Multisite to the Main Site?

How do I display all posts from multisite to the main site? Please help me. thanks.
-1
votes
1answer
21 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=...
1
vote
1answer
753 views

Filter Posts from the Main Query

I want to conditionally merge a custom post type with my posts post type, based on a custom field. If the field's value is 1, then I want I need those custom posts to appear in the same loop as posts ...
1
vote
2answers
651 views

Get user categories with most posts in it

I am trying to make a query to take first 3 categories with most posts per user, but no luck so far. This is where I am now: SELECT DISTINCT(terms.term_id) as term_ID, terms.name, terms.slug, posts....
0
votes
1answer
546 views

Get the tax term in which is a post via wp_query

I'll rewrite my original question because I feel like I can't be understood : I made a template page on which I have different WP_Query. I have a category taxonomy (countries). This template page ...
0
votes
0answers
44 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
1answer
629 views

How to echo woocommerce category name

Tried at least 5 SO answers, but nothing is working for me. I have this code and I want to output all the products within the category together with the category name on top: <?php $params = array(...
0
votes
1answer
689 views

Max Posts and Memory Limit

So I have a custom post type which uses ACF Metaboxes that contains over 750 posts and grwoing. I got the infamous white screen of death because it seems like PHP has exhaused it's memory limit ...
0
votes
0answers
8 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
25 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 ...
0
votes
1answer
29 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 ...
1
vote
2answers
612 views

Add posts to WP Query object

I need to filter the WP_Query object by adding some posts to it. I have the posts id's (from another SQL query). What would be the way to add (merge) new posts into the WP_Query object?
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'] = ...
0
votes
0answers
32 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
23 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
33 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
13 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(...
4
votes
2answers
46k views

WP_Query by a category id and a custom post_type

I need to query all posts that belong to a given category (default, not custom) and a custom post type. As simple as that. The fact that it doesn't work, to me, is ridiculous. Unless I'm missing ...
-1
votes
1answer
32 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
1answer
640 views

How can i see/log all requests coming from a registration form (not from the UI)?

I am talking about the REGISTER form PROBLEM: I have some requests that are coming from somewhere else - not from the user interface. I know this, because these requests don't have all the mandatory ...
0
votes
0answers
23 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' =&...
1
vote
2answers
975 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
1answer
517 views

querying data via $wpdb and get_row

I am using the Contact Form 7 Plugin to keep data of a form and I would like to query a table to show the results in a template. So this is what my query is: global $wpdb; $query = "SELECT count(*) ...
3
votes
2answers
527 views

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

I added the following to my functions.php: add_action('pre_get_posts', 'keyl_get_emp_posts'); function keyl_get_emp_posts($query) { if ($query->is_main_query()) $query->set('...
1
vote
0answers
84 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
2answers
21 views

2 column recent post query not respecting float right [closed]

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 ...
2
votes
1answer
47 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 ...
0
votes
2answers
731 views

pre_get_posts gives 404 error on Custom Post

I know this has been covered in different ways a thousand times (I read all the posts), but it seems not specifically for my case. I can't really get it to work myself, being a big development noobie. ...
0
votes
1answer
486 views

How to extract images of post and pages excluding header and logo image in wordpress?

I have tried this code to get all images from media library and i am sucessfully getting the source urls of all the images but now i want to exclude all the unwanted images like logo, header images ,...
0
votes
1answer
774 views

How to pass a php variable to js within a template?

I’m trying to pass a variable from the template to js, but with no luck. I’ve tried using wp_localize_script, and it seems to be working fine when attached to wp_enqueue_scripts action, but it doesn’...
1
vote
0answers
15 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
1answer
463 views

How to get value of a selected option from select tag and use it in WP_query to filter posts?

This is how I'm getting the value but how to use it in WP_Query so when I click Search to display let's say posts with Option 1 value? I'm doing this but don't know if meta_value is the answer $...
0
votes
0answers
38 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
49 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 ...