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

Pin posts to top of custom loop

Question What would be the best way to pin certain posts to the beginning of a custom loop that queries for many custom post types and may or may not have tax queries inside? Due to how the rest of ...
0
votes
0answers
25 views

Shortcode with 'year' parameter

I would like to display posts with a 'year' parameter. For example: to display posts from 2020, the shortcode should look like [archived-posts year="2020"]. I have tried my code below but it'...
0
votes
0answers
16 views

Filter WP_Query content depends on text inside

I have hundreds of pages and want to sort theme into 3 tabs: premium, senior and junior Here is my query $query_args = array( 'post_type' => 'page', 'post_status' => 'publish', '...
0
votes
0answers
12 views

What is Wordpress' control and data flow when loading a page (not template, post, etc) [closed]

Let's say I create a what in the Wordpress backend is called a page (pages - new page). I put some arbitrary page elements on it (e.g. title, text, some images, a widget or two displaying posts from ...
0
votes
0answers
24 views

wp_query and get_posts() in widget / own code

Could I theoretically use multiple php code areas / widgets in a page, each doing their own posts query and fetching with wp_query and get_posts() and use a page template that has no post loop?
0
votes
0answers
13 views

Apply category query clause to posts of custom type

I have succeeded at limiting the posts on my homepage to ones in a homepage category that I created by implementing the following in functions.php: function limit_category( $query ) { if ( $query-&...
0
votes
0answers
29 views

Custom Taxonomy Archive Page to display either ALL listings or only from URL

I'm using Toolset.com for Custom Post Types and Taxonomy and OxygenBuilder for page building in Wordpress. I've created a custom post type called Social Ritual (social-ritual) with a custom taxonomy ...
0
votes
0answers
13 views

Using Post Grid For Specific Category Posts Without Creating Pages for that Category

So I divided my posts into four specific categories. Now I used a simple href code, copied the category ID, and created hyperlinks to those specific categories from the main page. Now, basically, when ...
0
votes
1answer
7 views

WooCommerce sort by SKU

So, I've tried https://gist.github.com/bekarice/1883b7e678ec89cc8f4d on my website. It works good, as long as all the products have SKU. If a product doesn't have SKU, it's not displayed at all. This ...
0
votes
1answer
21 views

Get user posts with custom WP_Query on author.php

I try to show custom post list with WP_Query on author.php like this: <?php $args = array( 'post_type' => 'post', 'author' => 'get_queried_object_id()', 'posts_per_page' => 9 ); $...
2
votes
2answers
36 views

Compare two meta-fields in a wp_query (where meta-field-A is larger than meta-field-B)

I have a custom post type (foobar), with two meta_fields: updated_at build_ran_at I would like to make a single WP_query, that returns on the foobar-posts, where updated_at is after build_ran_at. ...
0
votes
1answer
15 views

WP_Query() not working as expected

I'm building a plugin for EDD which adds a custom metabox with checkbox option meta_key _xy_global_product. So far, so good. In the frontend, I'm trying to filter posts which have this meta_key set to ...
0
votes
0answers
27 views

Custom Meta Query doesn't work the same on two site

I'm building a query on a custom post type and some custom post meta. Here is the query : $meta_query = array( 'relation' => 'AND', array( 'key' => '...
1
vote
1answer
39 views

meta_query search names when they have middle initials

I have to build a search form where I search members of the company by their Full Name (First Name + Middle Initial + Last Name). All the names are in this form: John B. Doe The below code is working ...
0
votes
1answer
30 views

search blog posts by author first name and or last name

I am trying to create and endpoint where blog posts can be searched by author first name and/or last name. I was trying to do this with WP_Query but it uses the user nice name for the search which is ...
1
vote
1answer
41 views

How to use WP_Query without breaking the main Query

The WP Query class can be used to make almost any imaginable query to the WP database. It's amazing. But it's also used when WordPress is loaded, to run the main query for the current page request. A ...
0
votes
1answer
17 views

date_query in pre_get_posts out of memory

I'm trying to apply a Datefilter for specific categories. Wordpress crashs with a out of memory error. Is this a server problem or is my query wrong? At first I tried query -> (...) but with ...
1
vote
1answer
10 views

Add condition of user capability in WP_query

I am struggling a bit with my WP_query which includes a meta_query to limit posts based on ACF User field, but show all posts if user can 'edit_posts'. From my code below, the first two arrays work ...
1
vote
0answers
29 views

Creating a custom “Region switch” to filter posts query and save settings throughout session

I have one WordPress website that I want to make a "regional version" of simply by "filtering" which posts are queried while also using a "custom homepage" whenever a &...
0
votes
0answers
21 views

How to sort store location by specific category order in WP store locations

i want show if store has specific category then should be show in first and then order by distance add_filter( 'wpsl_sql', 'custom_sql' ); function custom_sql() { global $wpdb, $wpsl_settings,$...
0
votes
0answers
72 views

Excluding posts from search results page with meta query not working

On my search results page I have two loops. First loop displays post by meta value and second loop is "regular" loop that display posts by search query: <section> <div class=&...
0
votes
0answers
20 views

How to call my PHP function with AJAX ? wp_query

Im trying to build a product filter to display products depending on the tags this is the function in my function.php function product_filter() { $args = array( 'post_type' => '...
0
votes
1answer
19 views

posts archive page - closing WP_Query loop correctly [closed]

I am trying to use an example of the loop shown in this post Output yearly archive within a page to output post links grouped by year page-archive.php <?php /** * Template for displaying archive ...
1
vote
1answer
49 views

Get list of terms that have posts in another term

I have a product attribute called "color" and when I am on the archive page (e.g. color=blue) I want to display a list of all the parent product categories that contain products with that ...
0
votes
1answer
55 views

Pagination not working on custom query on a page

I have a custom query on a page (it is not an archive page), it works just fine, but I want pagination and it is not working at all... <?php $paged = (get_query_var('...
0
votes
0answers
18 views

How do you do a meta query on an encrypted field?

[province] => Array ( [0] => a:1:{i:0;s:2:"FL";} ) We're using magic fields and I want to do a meta_query on the above, but it doesn't work. $query = new WP_Query(array( '...
0
votes
0answers
20 views

custom post type and a “sticky” position taxonomy

I have a custom post type with a custom taxonomy that denotes various types of places the custom post might appear in the site. One that I'm having some trouble with is a "sticky" term for ...
1
vote
1answer
20 views

How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?

While searching with the argument s it adds additional value before and after each Like query SELECT wp_7_posts.ID FROM wp_7_posts WHERE 1=1 AND (((wp_7_posts.post_title LIKE '{...
0
votes
1answer
28 views

How I can change the condition or compare operator for WP_Query in pre_get_posts

So here is my problem I want to show Posts if have same category if not have post then show post of same tag. And to do that I am using "pre_get_posts" action. and setting query like ...
0
votes
0answers
19 views

WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)

I have a custom post type called "resource" where files are uploaded by admins and made visible to selected subscribers. I'm using Advanced Custom Fields (ACF) to create a field called "...
0
votes
0answers
11 views

How to rewrite with “tag” at beginning of url, e.g. /kids/post-slug-here

I would like to be able to rewrite the following url's, prepending a profile "tag" to the path, so that I can switch styles and content based on that profile. Just like with a language tag /...
0
votes
1answer
58 views

WP Pagination on Posts Search Results Page resulting from AJAX WP Query

I have a simple WP post query, which is supposed to load 8 posts per page, with a post navigation displayed below, like so: $query_args = [ "post_type" => "post", "...
0
votes
2answers
39 views

Query within a foreach within a query (queryception)

I'm achieving this list in a really roundabout way at the moment and I feel like I should be able to do it with a foreach instead of separate queries for each "House" (House is a CPT and is ...
0
votes
1answer
19 views

Counting instances of words in the results of a post query

I'm way over my head with this one and wonder if anyone can shine a light on where I'm going wrong. I am grabbing some authormeta for the resulting posts of a query, and I want to tally up the number ...
0
votes
1answer
15 views

Search filter between promo and exact price

I've got lots of posts with promotional prices and the rest have an exact price. I just wanted to make sure that if promotional price exists, use the promotional price as the target data when I try to ...
0
votes
1answer
31 views

WP Query Meta Value - How To Identify Specific, Unique Values?

On my Club Profile pages, I'm displaying a list of posts (Player Profiles) where the title of the specific Club Profile page is also a meta value contained in those Player Profiles against one or two ...
0
votes
0answers
25 views

query hook parse_tax_query function takes no effect

I'm trying to build a function (inside a plugin), which limits the shown posts to the time a logged in user is registered in weeks. (So if a user is registered for 4 weeks the categories page shoud ...
0
votes
1answer
14 views

How is $current_page passed in woocommerce_account_orders function?

The woocommerce function woocommerce_account_orders($current_page) has 1 parameter called $current_page. The function is called via woocommerce_account_orders_endpoint via the following hook - ...
0
votes
0answers
8 views

Query posts according to previously selected categories of logged in user

How do I query posts according to categories that a user selected at registration? The posts would be from a custom post type and match with existing post categories + custom field categories from ACF ...
1
vote
0answers
5 views

Display Featured Post by Categories and Avoid duplicated posts

I'm learning Wordpress development on Udemy and currently developing a theme. I haven't added any custom taxonomy but just using the "Post" and "Categories". Found a tutorial of ...
3
votes
3answers
201 views

Does WordPress sanitize arguments to WP_Query?

This is a very straight-forward question, but it's important and I can't find anything definitive in the docs. This question asks a similar question for the 's' parameter, specifically. I want to know ...
-1
votes
2answers
23 views

How to Delete Posts by title?

I have about 2000 titles. How can I automatically delete posts with these titles? For example
0
votes
0answers
20 views

Order post by modified date

I'm trying to return on the blog page the results in post edit order. Everything is working, I just have one problem. The first 3 posts in the blog are out of sync and are not being returned based on ...
0
votes
0answers
29 views

how to include author in custom post type search

I have a search field where a user can type in something to search a custom post type. This works okay if the word exists in the title but not in the content. Also, I want to include authors in the ...
0
votes
1answer
14 views

get term id from term name

Hi i am trying to get term id from term name (title ). <?php if ($_SERVER["REQUEST_METHOD"] == "GET") { // collect value of input field $nameb = $_GET['fname2'...
0
votes
0answers
34 views

Property 'post_type' of non-object produces Internal Server Error

Apache error logs have been auditing the following issue for over a week: [Thu Apr 29 19:50:24.673774 2021] [proxy_fcgi:error] [pid 19464:tid 139936082659072] [client 12.34.56.789:1000] AH01071: Got ...
0
votes
1answer
41 views

Wordpress sorting posts by date and title using a dropdown

I'm trying to set up a dropdown that would sort my posts by Newest to oldest and Alphabetical. This is what I have so far: I'm declaring an empty variable, then a form where I can change the contents ...
1
vote
0answers
25 views

Search by post title and content in wp_query without order

I am trying to do a search engine, I am using get_posts () function with parameter 's'. It finds me post by title and content but in a disorderly way, how could I tell it to first consult the titles ...
0
votes
0answers
15 views

How do I check if a NESTED ARRAY meta value array contains an item name? [duplicate]

I'm adjusting an archive page to only show products where a certain ACF meta field has a specific value but its not straight forward as the meta value is a nested array so I'm struggling to check if ...
0
votes
0answers
13 views

Get taxonomy name by tax-query in posts list

I have ajax category filtering and I use it to get taxonomy id and list posts by taxonomy. Now I want to show current taxonomy name in list view. I have trying to add <h4>get_cat_name((int)$...

1
2 3 4 5
107