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

How to check if logged in user have pending custom post?

I want to show a message to users who have their post pending for approval. I can do it with wp query like below but wondering if there is more efficient way, like a function; something looks like ...
0
votes
1answer
36 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
2answers
31 views

Order by meta_key doesn't work

I am using this code but it seems that ordering by meta_keys br_category first and br_name second, doesn't produce the correct results $args = array( 'post_type' => 'brands', 'meta_query' =&...
0
votes
0answers
18 views

Get taxonomy terms used in posts that have second taxonomy with specific term

I'm not sure I know how to phrase this question best, so please bear with me. I have a custom post type (artworks) which has two custom taxonomies attached (artist eg. name, and media eg. painting ...
0
votes
0answers
17 views

WP_Query Regexp whitespace and end of string

Hello I'm using ACL and I have trouble with REGEXP. I tried many ways but somehow it doesn't work. The meta-field is a ACL-Textarea. I need to search after searchword. After that word there may ...
0
votes
1answer
18 views

can I extend the WP_Query class to deal with 'duplicate' posts created by joining to wp_posts?

Based on the premise that one big database requests is better than many smaller ones, I've modified WP_Query for my custom post type 'word' and joined three tables to it. The resulting query looks ...
0
votes
1answer
22 views

Change normal grids to masonry grids

I'm currently creating a wordpress theme and so far all my code is working fine (my theme is based on the isotope js gallery), but I would like to transform my normal grids into masonry grids, could ...
2
votes
0answers
18 views

What's the point of the query_vars filter?

WordPress doesn't seem to support named parameters in a query string (like ?foo=123&bar=456) unless you explicitly allow them by doing add_filter('query_vars'...). Why is this? What (presumably ...
0
votes
3answers
90 views

Assign meta_query value to php variable

I am using this code for a meta_query $values = shortcode_atts( array('category' => 'Test',), $atts ); $args = array( 'post_type' => 'mytype', 'post_status' => 'publish', '...
1
vote
1answer
12 views

Loading the same WP_Query in two different wordpress .php templates

I'm successfully was able to load this WP_Query to my Wordpress template-full-width-home.php (page One) file: template-full-width-home.php <?php /* Template Name: Full Width (No Sidebar) Homepage ...
0
votes
0answers
22 views

Create Post Query to order by a Taxonomy custom meta field

I have a standard WP_Query to search for Posts of a certain Custom Post Type. I am trying to extend this by filtering by a specific custom meta field that was set for a Taxonomy that is attached to ...
0
votes
0answers
26 views

Variable ++ in query loop

There are 2 dynamic changing requiers thing in my html.they are "active" and "numbers (for example 1,2,3...)".I want write "active" into class if it is first element in query, else write only one ...
0
votes
0answers
24 views

Set ranking number orderby meta_key for specific Posts

I use a custom field totalreviews for rating my products I need to figure out how to get a rank listing like #1 OF 100Posts #25 OF 100Posts and display rank in single.php or homepage I did some ...
0
votes
0answers
17 views

WP_Query() displaying past post / event

I'm making a page for past events (using Event Expresso plugin) and I'm kinda confused about the wp_query. This one works: $atts = array( 'title' => NULL, 'limit' => 100, '...
1
vote
1answer
50 views

Load More Posts Button - AJAX

I'm trying to add Ajax to my theme so I can load my posts dynamically. The following code works but for some reason when I wrap the button that fires the loading with another div it doesn't do ...
0
votes
1answer
21 views

WP Query - Show custom posts only if user contain some user meta

I am trying to make a list of custom post type which going to show all posts but only if author contains custom user meta named "activeacc". So.. I have thic code... $args = array( 'post_type' =&...
0
votes
0answers
15 views

Wordpress pagination links with query args

I have set some arguments to the paginate_links function and managed to do pagination with query args instead of path, but on the first page it does not rewrite my arguments, it just keeps the current ...
0
votes
1answer
21 views

How can I query and sort custom-post type using WP_Query

guys, I have a custom post type called "game" and it has some custom fields (get_post_meta) which I access by their keys "_game_date_key", "_game_home_goals_key" and "_game_away_goals_key". How do ...
0
votes
0answers
12 views

Custom order of posts in wp_query and different taxonomies

Say I have the following: Post IDs: 1,2,3,4,5,6,7,8,9,10 Category: A, B, C, D, E I want to create A page that will contain Taxonomy A and have the following Post IDs in the following order: 4, 6, ...
0
votes
2answers
29 views

order posts by a secondary query that counts items

i'm working on a music plugin. It uses a custom table tracklist_items to store every tracks of a playlist; which has a structure like this : |id| |track_id| |tracklist_id| |order| |time| So if I ...
0
votes
1answer
21 views

Result of Custom WP_Query appears on 404 Page (but result are found!)

I wrote a custom search page. It was working well then I added additional changes, now I got 404-Result-problem. The problem keep there even I did revert (I have backup) and I cleared the cache. I'm ...
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
44 views

wp_query with meta_query and tax_query

I am trying to find a way to combine a meta_query and a term_query and i got confused with the research. $sport = 'basket'; $args_p = array( 'posts_per_page' => 10,...
0
votes
1answer
21 views

WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)

This is really confusing me. I've tried numerous things but cannot get appropriate results. Here's what I currently have for my query: $args = array( 'post_type' => 'product', 'tax_query'...
0
votes
1answer
20 views

WordPress live search and filter custom fields

I have the following code intended to fetch, filter and display custom post on input(onkeyup). However, it sin't working at the moment; I also get a 500 (Internal Server Error) when I open the console....
0
votes
0answers
24 views

Pass post ID to JavaScript outside the loop

I try to pass the post/pages ID to my JavaScript file. url and template_url works but the id just return 0 on every post. PHP: // Register scripts wp_enqueue_script('scripts', ...
0
votes
0answers
21 views

WordPress live search and filter

I have a grid of posts on my archive page. How can I filter through them once I start typing on the search bar, or filter by category on click, please?
0
votes
2answers
61 views

wp_query is showing posts from other categories

I am trying to make a custom loop that will display the latest 5 posts from select categories, all using a single query. I want the loop to display the category name followed by the 5 posts, and then ...
1
vote
0answers
17 views

Orderby is working with one query but not with other

I'm using a shortcode to show some price boxes. I use a CPT with a custom field called 'posicion' which has a number that I use later to customize the loop. This is the code: <?php if ( ! defined( ...
0
votes
1answer
17 views

Query for current post

I want to show current post.I will use this query in single template for custom post type.When click the custom post type, only the post will shown. How can I write this query? In wordpress ...
0
votes
0answers
14 views

Try to fix Image outside <a> container

I am using the latest Twenty eleven theme/Wordpress and Woocommerce. Some pages with shortcode such as [woocommerce_cart] without contents came out with the image outside container problem. See the ...
0
votes
1answer
10 views

How to search through all child taxonomies using WP_Query?

I need to create a page in which I can search through child taxonomies(custom child-category) based on GET request (For example $_GET['search_cat']) using WP_QUERY. I just want to list all of the sub-...
0
votes
1answer
30 views

Multisite how to display merged posts from two sites and sort by latest date?

I'm using multisite and pulling blog posts from 2 sites. The below query displays the posts but does not merge the posts together, it just lists all of site 1 posts followed by site 2 posts and ...
0
votes
1answer
15 views

How to use wp query in my custom page without including header and footer in wordpress

I am loading a php page using ajax. But I am not able to use the wp-query function on the custom page. Can anyone please suggest to me how I can use the wp query function on a custom page without ...
1
vote
1answer
47 views

How to make this WP_Query run faster on a WordPress website?

This code is part of a custom WordPress homepage that shows the 7 most recent posts using WP_Query, and the first post has a custom html structurer, while the rest has another html structure. Then ...
0
votes
1answer
25 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
1answer
25 views

Custom query result empty on page 2

I'm trying to filter paginated results of my custom query. I've got 4 posts, 3 per page, total of 2 pages. When I apply the filter while on page 1, it works. When I apply the filter while on page 2, ...
0
votes
0answers
30 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
0answers
11 views

how to display the number of posts in different on pages 1, 2 and 3

I want to create a page that displays the following number of posts. Page 1 or home = 7 posts Page 2 = 5 posts Page 3 and so on 15 posts. What is the code to display it?
1
vote
1answer
42 views

Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first

I want to order a WP Query result by a numeric meta value in PHP. To achieve this, I am doing as follows: $query->set( 'meta_query', array( 'relation' => 'OR', array( 'key' =&...
1
vote
1answer
28 views

meta_query in WP_Query value is not accepting array

I'm trying to pass an array of values into a meta_query value. // Works as expected to return posts with 1474 in featured 'meta_query' => array( array( 'key' =&...
0
votes
1answer
47 views

how to display posts content on the custom css popup by clicking on each title on the sidebar?

I want to display post titles based on post_tag from default post_type concat with post_category from another post_type named 'update' on the sidebar. And finally When users click on each title it ...
1
vote
0answers
21 views

How to get the post ID's of the five most recent posts [duplicate]

How can I get an array with the post ID's of the five most recent posts? I need it to exclude those posts from a WP_Query / get_posts(). I need a WP_query that skips the first five posts and starts ...
4
votes
1answer
69 views

How to exclude latest x posts from a paginated query?

I have a WordPress loop, that is part of an AJAX call. Every time a button is clicked, this function is called, runs the below loop and outputs the next 6 posts. There are already five posts shown by ...
0
votes
0answers
6 views

Shared taxonomy and query performance

I have a question about shared taxonomies. I have 6 multiple custom post types and each of them should be categorized by a City. They're different CPT because each of them comes with a rather ...
1
vote
1answer
21 views

How to loop for every result found in the_content() when using the search query?

im doing a custom search result page with function that extract from the_content() some words before and after the search query. (Eg ?s=cool result=[...sterday was cool and the par...] It's working ...
1
vote
0answers
36 views

How to prevent WP_Query function from returning all posts when empty?

For example: function getBlogFeedPosts($settings, $featuredPosts, $exclude_array, $numPosts, $offset) { $mbaQueryArgs = [ 'post_type' => 'post', 'posts_per_page' => $numPosts, ...
0
votes
1answer
19 views

exclude product with available tag

I have classic WP_Querry: $products = new WP_Query( $args ); with $args = [ 'post_type' => 'product', 'posts_per_page' => 500, 'product_cat' => 'cars', ]; If I want products ...
0
votes
0answers
21 views

Get Posts from Specific Custom Post Type Seperately on Taxonomy Page (tag.php)

I am trying to Get List of all custom post type (Album) for the current tag (post_tag) page (tag.php). Lemme explain further: E.g I used Drake has a post_tag taxonomy while posting Albums (album ...
1
vote
0answers
30 views

Make a page return false to is_single() and true for is_post_type_archive() before wp_enqueue_scripts

I am using a page to replace custom post type archive. I used page template in that page to query CPTs like a CPT archive The problem is, since I conditionally load different css files based on the ...