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

Custom post WP_Query infinite loop error

I am trying to build wp_query loop with custom post type and it seems I get the infinite loop as the result. Here is my code that I am using: $apartargs = array ( 'post_type' => 'apartmani', ...
1
vote
3answers
14k views

How to query posts from specific authors and categories using WP_query?

I currently have a WP_query where I am getting posts from a specific set of authors. To this, I want to add specific categories as well. $args = array( 'author__in' => $authors, 'posts_per_page' =...
0
votes
1answer
24 views

WP_Query of custom post type sorted by meta_key has unexpected results

I do not understand why my code outputs the events in a seemingly random order. It's not sorting by the start_time as I would expect. <?php $args = array( 'post_type' => '...
0
votes
1answer
3k views

forming WP_Query for posts of all post types but from specific categories

I need to get post from blog, custom post type 1, custom post type 2. custom post type 3 and either from category 1 or category 2 or category 3 or category 4 or category 5 or category 6 or category 7 ...
0
votes
1answer
709 views

Wp redirect to url with ampersand string

i have a url like this: www.url.ui/?keyone=valueone&keytwo=valuetwo&ekythree=valuethree stored in a variable: $url = www.url.ui/?keyone=valueone&keytwo=valuetwo&keythree=valuethree ...
0
votes
1answer
27 views

Move some posts to end of sort order, even if there is a sort in the wp_Query already

I have a site that lists properties for sale. I have a custom wp_query, with a sort dropdown I created. This dropdown reorders the posts query by date, price (low-high & high-low) and beds (low-...
0
votes
0answers
21 views

How to display custom search results from a selected category of a custom post type?

I have a website that has a blog and a custom post type called proyecto. They are on mywebpage.com/blog and mywebpage.com/portafolio.Each of those pages have a search field and category dropdown ...
0
votes
1answer
905 views

Get post from Category by Priority

I want get 3 posts from event custom post type. But i want to do that by category priority. If "featured" category has 3 upcoming event then i want to show 3 posts from it, if "featured" category ...
0
votes
2answers
1k views

Custom search: Search posts but display parent page in results

I'm using Wordpress 3.5.1 with a modified twentytwelve theme. My main site structure is based on the Smooth Slider plugin (jQuery Cycle). I have Pages that contain only a shortcode (for example, [...
2
votes
2answers
1k views

How to display custom field on homepage

I am new to custom fields thing. I am working on a movie review site. And wants to add movie story or plot field, I have successfully added the custom field named Story and its content is displaying ...
0
votes
1answer
19 views

Use WP_query to match post types based on custom field values

i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean. For example: i have a ...
0
votes
1answer
768 views

How to get post meta for custom post type and taxonomy

I am trying to access post meta for custom post type and taxonomy using WP_Query and then query the posts with that specific post meta. So far I have tied the following code: $hot_args = array( ...
2
votes
2answers
254 views

How do I create an archive page for standard posts?

I've been tasked with creating a portfolio website for a client who also wants a blog. What I've Done Thus Far: I’ve created a custom post type to separate the portfolio work from the blog posts and ...
0
votes
2answers
16 views

How select query is generated in a Custom Post Type?

I have this table that is generated in a Custom Post Type (CPT) Is there an option that I can modify the query? For example, I have this post_type = 'my-type' in wp_posts table. I want to do a JOIN ...
51
votes
3answers
62k views

Query all posts where a meta key does not exist

I am trying to get a query to retrieve all the posts where a specific meta_key does not exist and then create it. I am having problems finding those posts as the query I am testing does not seem to ...
0
votes
2answers
814 views

How to query images from a post to use in a slider

I am trying to pull images as attachments from a particular post (custom post), ...and I'm using the example within WordPress codex codex example to display all images as a list ...except the images ...
1
vote
2answers
892 views

Exclude current post when getting related post on custom post type and taxonomy

The below will return the other post in the same category but it will also return the current post too. Is there a way to exclude the current post from the query? $args = array( 'post_type' =&...
0
votes
2answers
709 views

Comparing timestamps in meta query doesn't work

I want to compare two timestamps in a meta_query instead of comparing two dates in the "Y-m-d" format, each of them stored separately in custom fields, but no success. The first timestamp is an event ...
1
vote
0answers
16 views

Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?

Here's how I'm doing it atm. $query_vars['paged'] = $_GET['page']; $query_vars['posts_per_page'] = $_GET['posts_per_page']; $query_vars['post_status'] = 'publish'; $query = new WP_Query( $query_vars ...
0
votes
0answers
10 views

Filtering get_terms loop by custom fields & custom taxonomy

On specific page I’m displaying posts from my CPT („opencourses”). Posts from this specific CPT are grouped by custom taxonomy („kategoria”) - this piece of code works. At the same page I have four ...
1
vote
2answers
1k views

The pagination on index.php doesn't work on a first page

I have index.php with a pagination. The permalink settings is plain permalinks. I have a correct pagination view when I open a page /?paged=2 but if I open just index.php I have all posts without ...
0
votes
1answer
33 views

Custom WordPress post query for displaying time-released content on website

I am trying to implement a "content drip-style/time released content" subscription system using a WordPress query that filters and selects content from a custom post type using set parameters and ...
0
votes
1answer
23 views

Foreach-generated custom tax queries, each with an ajax “Load more” button

I'm looping through custom taxonomy terms to create a WP_Query for each term, then displaying the posts on the front-end. I'm also attempting to adapt this helpful tutorial(and accompanying comments) ...
0
votes
1answer
17 views

1500+ duplicate queries via get_option function (query monitor)

I'm having a huge performance issue once I'm logged into Wordpress. Query Monitor says it's doing over 1500+ duplicated queries with the get_option function executing this query: SELECT option_name, ...
0
votes
1answer
23 views

Custom query for certain post type OR another post type with a certain category

I want to display posts that are either EITHER Post Type A OR Post Type B but ONLY if they are also in CATEGORY 1 Is that at all posible? How do I built my custom query?
0
votes
1answer
2k views

Custom post archive with search, is_search() is false?

I have a custom post type, and have created an archive template, archive-custom_post_type.php, which includes a search form. I am then using pre_get_posts to add parameters to the query to filter my ...
1
vote
1answer
897 views

Get post ID's from one query and exclude from another

I have 2 instances of the WP_Query class, one showing 4 "Featured" posts and another showing "basic" posts. What I want to do is exclude those 4 latest "Featured" posts from the basic query. I assume ...
0
votes
1answer
16 views

WP Query search for attachments and their exact title

Due to lack of reputation, I must now ask the question. I want to create a search for all images in the media libary. The search result should only appear if you search for the exact title of the ...
0
votes
1answer
15 views

how to handle multiple ajax wordpress queries?

I am having a problem with two ajax action. I have a post grid it has a frontend sorting "ASC" and "DESC". So if I click on "DESC" it changes the WordPress query arg "order by" to "DESC". It works. ...
0
votes
2answers
1k views

Masonry layout within the loop

I have tried to to make a custom query, to some extend. it is working fine. But where i cannot make it work, is it to break after every 3 posts and do same thing (print div.row) and run same loop, For ...
1
vote
1answer
424 views

Why is my category template ignoring post type?

I am currently working on two sites that make extensive use of custom post types. For both we have a defined number of items (cpts) that fall under a particular bucket (categories). One of the sites ...
0
votes
0answers
37 views

Trying to display related custom posts only in same child taxonomy as current custom post

I have some custom post types 'home' and 'provider' that share a custom taxonomy 'states'. The taxonomy is hierarchical so Georgia is a parent of Atlanta etc. In the single template for the post type '...
3
votes
1answer
2k views

paginate_links ignore my format

I need the pagination liks to have the url, like: current_url?p-page=1 current_url?p-page=2 current_url?p-page=3 And so.. The reason I need this is because I have other params in the page. the ...
1
vote
1answer
2k views

How to get list of posts from permalinks?

I am using an API which tracks metrics on parts of my site. The only useful bit it saves though is the URL (permalink). What is the most efficient way to query up all the posts that match those ...
1
vote
1answer
462 views

Pagination links missing for first link (1) and previous button? How to get pagination links to work?

I'm trying to add pagination to my WordPress query using pagination_links() however I am getting no links returned for my page 1 links and previous link? Other links are adding the paged query string ...
4
votes
1answer
451 views

Query two taxonomies via URL or link?

I've been banging my head about this, and have created a work-around, but it would be much nicer for my site's organisation if I could figure this out. I want to be able to query posts across two ...
3
votes
3answers
948 views

new WP_Query() - what is the earliest valid hook?

Specifically, is it valid to run a new WP_Query() during the plugins_loaded action?
0
votes
1answer
439 views

change posts_orderby of the callback wp_query?

I found this answer that helps with ordering query results by the post type in my search query. But the issue is that it helps when I go to https://example.com/?s=query%20string that is if I search ...
0
votes
1answer
1k views

Woocommerce pagination not working in custom loop WP_Query

Please help with pagination I have code that works fine (functions.php) function projects_custom_number_of_posts( $query ) { $query->set( 'posts_per_page', 2 ); return; } add_action( '...
0
votes
2answers
1k views

SQL returned by Wp_Query has wp_posts.ID = -1

I have a custom loop based on these arguments (below), and for some reason when it's run, the SQL returned has this fragment: ... AND wp_posts.ID = -1 ... And I get no results from the db. If I run ...
0
votes
0answers
8 views

Query BETWEEN timestamps (today and in a custom field)

I am using wordpress 5.3.2 and advanced custom fields pro Version 5.8.7. My custom field is called timestamp. See below my ACF configuration: I tried to query the db like the following: ...
0
votes
1answer
1k views

Custom post type loop error: Trying to get property of non-object

A plugin I am using creates a custom post type for articles ie. 'ht_kb'. In my themes front page I have a custom loop displaying recent posts of the standard 'post' type. On the same front page I ...
1
vote
2answers
960 views

the_post() within switch_to_blog() altering my excerpt

I have a strange problem I'm facing when using WP_Query with multisite in a plugin I'm writing which hooks into add_meta_boxes. I'm wanting to display all post titles in a dropdown in a meta box. ...
0
votes
2answers
472 views

wpdb LIKE request shows all database data

I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i'm getting now. I understand I should use the % before and after the $name only nothing seems to be ...
0
votes
1answer
1k views

Creating a navigation menu of all posts of a custom post type and their children posts?

I have a drop down menu that displays a link (the permalink) to all of the posts of a custom post type (county) and would simply like to display their children too this is the code I have so far but ...
1
vote
3answers
941 views

Loop to fetch 3 post_thumbnail instances from 3 most recent custom post types named “portfolio”

I am trying to display 3 post_thumbnails from a custom post type "portfolio" on my homepage template. So one from post 'A' , one from post 'B' and one from post 'C' The image from post A will be set ...
1
vote
1answer
2k views

Woocommerce - Changing the order of the upsell products

Having some trouble with a clients site. We have a product with four upsell products linked, and they display on the site. Only problem is, those products are listed on the page in a seemingly random ...
0
votes
1answer
2k views

Display Wordpress Post By Date

I want to show Wordpress post by day/date in homepage. ex: Monday, January 03 post 1 post 2 post 3 Sunday, January 02 post 1 post 2 post 3 Saturday, January 01 post 1 post 2 post 3 What ...
3
votes
2answers
1k views

How do I order pages and categories by ID or name in the same query?

I would like to query most of my pages and categories on the homepage. So far I am able to get the pages and category (posts), but I cannot order the list the way I want to. I want to be able to get a ...
0
votes
0answers
14 views

Get categories within specific term

I have a WooCommerce shop, where I'd like to show every possible product category, where the products have a specific attribute (term). Say I have a product attribute called: "Designer", then I wish ...