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

Why does get_posts only show results for Admins or logged-out users?

I use a get_posts() call with these arguments: array(6) { ["include"]=> string(14) "1633,1634,1635" ["post_status"]=> string(3) "any" ["post_type"]=> string(10) "attachment" [...
0
votes
1answer
19 views

get_posts query is taking about 40 seconds to execute

I have a meta query in get_posts that's taking a ridiculously long time to complete. It works fine, but it just takes way too long. I have a custom post type named event. On every event post, there is ...
0
votes
1answer
4k views

Why does 'exclude_from_search' exclude a custom post type from WP_Query?

In WP 3.1, it appears that setting 'exclude_from_search' = TRUE for a custom post type excludes the post type not just from searches on the front-end, but also from any post query using 'post_type' = '...
1
vote
1answer
1k views

Wp query show post by author name or post title or post content

I have to create a search query which allows me to filter all posts where author name and post titles or post content has the word from search textbox. So if i search wordpress it should list all the ...
0
votes
2answers
1k views

insert thumbnail image from php script

I'm trying to insert a post image thumbnail from my php scritp. It's inserting the post, the content, a download link, and I only need to set the thumbnail image to finish my script. This is my code ...
0
votes
1answer
922 views

CPT post doesnt shows tags and category on backend admin page

Few days ago updated my wordpress(on local host) to 4.8, on update the categories and tags for cpt post which has assigned 'hierarchical=> true' for using 'page-attributes' has stopped displaying on ...
2
votes
2answers
1k views

Change default ordering of taxonomy terms - pre_get_terms

I wanted to change the default taxonomy terms order by its 'term_order' value instead of 'name' in admin side. So I tried something like below. But it doesn't work and php memory exhaust. function ...
0
votes
1answer
721 views

Custom taxonomy and query multi conditions

I have this query $query->set( 'tax_query', array( 'relation' => 'OR', array( 'taxonomy' => 'location', ...
0
votes
0answers
9 views

create a custom query for posts managed by Restrict Content Pro

I'm using the popular membership plugin Restrict Content Pro. I'd like to create loops that query for posts that are being marked as being restricted by RCP. How can I do this?
0
votes
2answers
17 views

Get posts that do not have the same tags as current

I'm trying to get all posts in a custom plugin loop that DO NOT share the same tag as the current one. I'm trying: $events = tribe_get_events([ 'start_date' => 'now', 'eventDisplay' =&...
0
votes
1answer
13 views

Is this meta query problematic?

I have couple of checkboxes determine the range of min and max people capacity for events. For example: 0 to 100, 100 to 200, and so on. I need to filter them through with a meta query but currently ...
0
votes
3answers
697 views

WP_Query returns empty if meta_query has more than 7 values

I have a custom loop to display a custom post type 'properties' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if ...
0
votes
0answers
15 views

Sort custom post by custom field if none order by latest release

I basically want my post order first on upcoming releases and if there are non or no more I want to order them by latest releases. I would also like the upcoming book releases to be ordered by nearest ...
1
vote
0answers
73 views

wp_query ignoring custom post_status

I have a custom post status called 'dead.' I am trying to create a wp_query to show all posts for a custom taxonomy. If I specify 'any' for the post_status I do get published posts and my 'dead' ...
1
vote
3answers
1k views

How to retrieve current page WP_Query arguments?

Context I'm developping a plugin showing geolocated posts on a leaflet map. I want to add a shortcode parameter to show a map with only the current loop posts' markers. That feature would be great on ...
1
vote
1answer
1k views

Why is wp_query causing an uncaught error to is_user_logged_in() not defined?

I am building a plugin and have used the simple query: function getTotal($postType){ $total = 0; $args = array( 'post_type' => $postType, ); $metrics = new WP_Query( $args ); ...
0
votes
4answers
17k views

Order taxonomy terms in alphabetical order

I have the following query: <?php $args = array( 'hide_empty' => false, 'orderby' => 'title', 'order' => 'DESC' ); $terms = get_terms( 'projets-location', $args ); if ( !...
1
vote
1answer
1k views

Combining categories (Query posts with multiple taxonomy terms)

I'm attempting to display a list of all posts from multiple categories (if anyone answers this, you might want to include combining tags as well, as probably that will make this answer comprehensive ...
0
votes
0answers
25 views

How to combine meta_query and date_query with condition in Wordpress

I have a problem with the combination of meta_query and date_query. I have meta_data with key is start_time. I want to query with the condition: if start_time is not empty then use with condition '...
0
votes
1answer
830 views

Hierarchical List Pages as a table

I need to generate a list of all Wordpress Pages and have them display in a HTML Table, that will be printed for offline use. First column is Blank Second column will have the Page Creation Date ...
0
votes
1answer
2k views

WP Query - Search in title or author_name

My need is to have a WPQuery that searches for posts which title is 'test' OR author_name is 'test'. Here is the code I tried: $search_query = get_search_query(); $args = array( 'relation' =>...
0
votes
1answer
765 views

Pagination is not working on custom query inside a custom home page template

I know this is a duplicate question. But to comment on existing question, I dont have enough points. So here we go.... Pagination is not working on custom query inside a custom home page template. ...
0
votes
1answer
2k views

Checkbox field that add a subscription product and change prices of other products in checkout and cart page

In Woocommerce checkout section, I am trying to add a checkbox that adds an additional subscription product. It is working fine and I took help from here One more requirement is that if there are ...
0
votes
1answer
689 views

Selecting posts older than the current Unix epoch timestamp

I am trying to perform the following query, which originates by the fact the post's 'date' and 'time' are entered as separate custom fields. $args = array( 'post_type' => 'some_kind_of_posts'...
0
votes
2answers
870 views

How to fix pagination for custom loops on front-page.php

A search on this topic on this site throws up a lot of results claiming to have resolved this issue, but I am having a contrary experience after implementing these guidelines as outlined here: How to ...
0
votes
1answer
19 views

the_posts_pagination() not working in wpquery

I'm trying to create pagination to the custom wp_query here is my code: <?php $btpgid=get_queried_object_id(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = ...
2
votes
1answer
7k views

How to create/modfiy WP_Query to search in post title OR custom field?

I need to modify or create a WP_Query that will search for a search term in both the post title OR a custom field (called 'my_field'). I have been reading and trying for hours, but I am right back to ...
0
votes
1answer
23 views

Which meta_query and post_content blend is better in WP_Query, performance wise?

I need to WP_Query for posts which: either have a postmeta 'answer' set to 'yes', and whatever post_content; or have 'answer' set to 'no' but only if post_content is empty. So in an ideal world ...
26
votes
3answers
6k views

Can I force WP_Query to return no results?

I'm working on a website with a search feature that allows users to search through a lot of post meta. There is a specific search pattern that I would like to forcibly return no results for. The ...
1
vote
1answer
765 views

Mixing 2 custom post types with posts output in specific pattern

I'm trying to build a structure like this (see most excellent diagram) with two different CPTs, Videos and Ads. I want to blend the two post types in the same wp-query so they are output in a ...
0
votes
0answers
7 views

Customize the Sorting Dropdown in WooCommerce use another list or more page

it would be great if there was a way to change the default sort by dropdown in WooCommerce on the shop page. but I want to use list page or other page for default sort by dropdown in wp-query.
0
votes
1answer
29 views

Pagination of custom page with custom fields query

Hello I have created a custom php file that I use to show specific posts by value inside the a custom field. So for example I have 100 posts, let's say they all have custom field MyTitle and 10 of ...
0
votes
0answers
26 views

How to Join wp_posts & wp_postmeta table using custom query

I am trying to create pagination for product details with the help of wp_posts & wp_postmeta table for my woocommerce custom code for admin area. There are 85 products in shop & i want to ...
0
votes
1answer
1k views

Display Year and Month from custom field + Age Calculator

I have a custom field "DOB" on my custom post type which is in [Ymd] format. I want to compare that date of birth to current time and want to show "You are # years # months." I am able to calculate ...
1
vote
1answer
3k views

How to filter my search in post if contains a word in title, content or excerpt?

I'm trying to filter one search, and I'm interested in know if a word is inside the title, the content or the excerpt but without luck and finally I'm stucked. $args = array( 'post_type' =...
0
votes
1answer
1k views

WP_Query showing all posts, except from category X, unless it's also in Y

I'm trying to show posts from categories A, B, C, D...and Y, except X, unless posts in X are also in Y, then show them with the rest. I can hide category X on it's own pretty simply: $args = array( ...
2
votes
1answer
1k views

Wordpress WP_Query orderby being overwritten

$args = array( 'post_type' => 'mcm_company', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => '1000', 'post_status' => 'publish', )...
1
vote
1answer
1k views

get_post_meta slowing down my page load (in a plugin)

I've been working on this project where I need to load events (custom post type) and a whole bunch of meta data for every event. The problem is that page loading times are getting longer and longer ...
0
votes
1answer
1k views

Query Pulling the same post twice

After seeking help and failing, I managed to write a query for Wordpress that does exactly what it's suppose to do, however it pulls the post that it's suppose to in twice. I've stared and stared at ...
0
votes
1answer
2k views

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
1answer
1k views

new WP_query using custom fields

I am trying to query child posts from two parents (that part is working fine), ... but now I want to exclude posts that have a meta_key of 'feature' with a meta_value of '1' Using the Codex ...
0
votes
1answer
1k views

How to search posts by title with special characters in WP_Query?

I have built a custom query for a website where I have a custom post type named "Program" (i.e). On this custom post type, let's say I have the taxonomy "Level" where I have some choices. The way I ...
0
votes
1answer
982 views

WordPress: Cron locking and Queue

I have some CPU intensive scripts that I don't want to run concurrently. Every now and again the scripts will overlap and crash the server. Already at 2GB and the mysql container still crashes. I ...
25
votes
1answer
118k views

"tax_query" parameter not working with WP_Query

I have a custom post type called 'episode'. Attached to 'episode' I have a custom taxonomy called 'video_type' that contains two terms: "bonus-footage" and "episode"; "episode" contains two child ...
0
votes
1answer
830 views

Not able to fetch woocommerce variation sales products for particular category products

Not able to fetch variation sales product according to particular product category . My code fetch only simple products not variable products. $cat_id = $_GET['catid']; $args = array( '...
0
votes
1answer
923 views

I cannot get tax_query in get_posts() to work with custom taxonomy

I have been trying to achieve this for the past two days but nothing works. I am attempting to build functionality to search any post, page, and a couple other custom post-types by a tag. I have ...
5
votes
1answer
21k views

Use WP_Query with have_posts()?

Is it possible to use $items = new WP_Query( $query_args ); with <?php if(have_posts()): ?> <?php while (have_posts()) : the_post(); ?> without changing the loop to be <?php while ...
0
votes
1answer
23 views

How to group only VISIBLE posts? [closed]

Good afternoon With the help of a fellow user here I am finally able to display all posts on a single page with the respective post month as a divider between the groups. So it looks something like ...
0
votes
1answer
24 views

How to display all posts divided/ordered by post date? [closed]

Good afternoon My task is to display all posts on a page, with the respective post month as a separator. So something like this: January 2021 ----------------- post 1 post 2 February 2021 ----------...
0
votes
2answers
35 views

Is it safe to access the underlying mysqli object from \wpdb for custom queries?

I am writing a custom (bespoke, for 1 client, not for publication and general consumption) plugin, that needs to access custom tables. In general with WP,I follow the principle of using the higher ...

1
2 3 4 5
109