Questions tagged [query-posts]

Set up The Loop with query parameters. This will override the current WordPress Loop and shouldn’t be used more than once. This must not be used within the WordPress Loop.

Filter by
Sorted by
Tagged with
0
votes
1answer
17 views

How to query for all posts that have a particular meta key?

I have many posts. Some have meta data, with a key called "foo". How can I query for just the posts with the meta data "foo"? metadata_exists requires the post ID, I'm trying to ...
0
votes
0answers
14 views

Elementor custom query get all terms - Custom taxonomy in Post Types product

I try to perform a custom query, but without success. In the post type of products I created taxonomy - designers I need to create a query that will show me all terms- designers. Thanks for the ...
0
votes
2answers
39 views

How to check in functions.php if there is data in a WP_Query?

I have 2 different WP Query on the home page. I need to check $home_query condition in functions.php then I want to do something if $home_query returns null. I tried with pre_get_posts action I couldn'...
0
votes
1answer
28 views

How can I exclude the latest post from the front page?

I'm trying to exclude the latest post from the homepage/archive page. The closest I've gotten is by using this. function exclude($query) { if ($query->is_home() ) { $query->set('...
0
votes
1answer
43 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
1answer
18 views

How do widgets access posts they should display?

How do widgets embedded in a page access posts they should display? How do widgets (php code) in the page access the posts they should display (via the used template's post loop / with wp_query and ...
1
vote
1answer
21 views

Does Wordpress run a post query when a page is invoked?

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

How does post loop integrate individual page elements

I am just trying to understand how coding in Wordpress works. I have read a bunch of tutorials about post loops and how to modify them with queries, but I have no idea how individual page content I ...
0
votes
2answers
45 views

how to load random related posts with specific custom fields?

I want to load 3 posts that have the same custom field value as the current post. for example: The current post has 3 custom fields: color: black background: red lastname: doe Now I want to load ...
0
votes
0answers
42 views

Tax query get first product with attribute value in pre_get_posts

We've got a webshop with over 3000 products. Some products have the same attribute value for pa_model, as shown below. Productid 1 - pa_model Nike Productid 2 - pa_model Nike Productid 3 - pa_model ...
0
votes
1answer
59 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
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 ...
0
votes
1answer
13 views

Loop through posts of only 2 statuses

Setting up a visibility condition for a widget - i need it to apply to the posts in a certain term but only those of "pending" and "publish" status. this essentially hides the &...
0
votes
1answer
23 views

Targeting custom post type via functions.php doesn't work

I have a custom post type, books, set up and a custom taxonomy, book_cat, to act as categories for these posts. I've added the below code to functions.php to sort posts on my custom taxonomy archive ...
0
votes
1answer
64 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
0answers
26 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
78 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 ...
0
votes
0answers
26 views

Updating post count on admin page after pre_get_posts filter

After the pre_get_post filters out the past posts, the number of posts above the page is still the original count of all posts (custom post types). How can I update that number so it'll correspond ...
0
votes
0answers
18 views

How to get max value of filtered query post

I have a query post to filter my post in my CPT, filtered on front end by a form filter. The problem is that with different filter, I have different max value. For example I have the following custom ...
0
votes
0answers
12 views

How to create loop of posts except post ID defined via ACF field

I am creating a custom news page with two columns - 1st column - featured post - using a ACF text field to add post ID to show, ie: 12345 - works fine. 2nd column - remaining news, showing all other ...
0
votes
0answers
16 views

Allow users to subscribe to posts submitted by a specific user and/or user group and display those posts in posts index feed

I have a WP project that requires a complex set up. I'm trying to set up my WP site to allow Company Profiles which are basically user groups. In the group users that belong to that group will be able ...
0
votes
0answers
71 views

Duplice post with standard WP loop - fixed by using query_posts() instead

I have an index.php file on a website designated as the blog page. I have an archive.php file which handles all the subsequent category pages. I ran into an issue on the archive page, where for one of ...
0
votes
3answers
26 views

How can I show only 5 posts from the relationship?

HI I use plugin: Advanced Custom Fields How can I show only 5 posts from the relationship? This is the code: <?php $c_lists = get_field( 'c_lists' ); ?> <?php if ( $c_lists ) : ?> <?...
0
votes
1answer
39 views

find custom post type post by searching its custom field with my string

I have a custom post type called series and each post has a custom field named originaltitle. So in my code before I create a new post, I need to check if there is already a "series" with ...
1
vote
1answer
21 views

Fetch Record based on meta key dates

I want to write a query which fetches the data based on my meta key added. Meta key name is 'repeater'. This is my POST META. Serialized: a:3:{i:0;a:3:{s:9:"postdates";s:10:"2021-02-02&...
0
votes
0answers
50 views

ElasticPress is (aparently) messing with my search filters

I recently installed ElasticPress on my woocommerce store, and it's working fine -- the product page is showing normally, and the search bar is working fine with the new elastic capabilities. However, ...
1
vote
1answer
13 views

Show Only Posts Owned By Logged In User + my post

I would like to restrict access for logged in users to specific posts: their own posts and my posts (as they will serve as templates for them). I find this code snippet that works perfectly to show ...
0
votes
0answers
13 views

how to display posts of events that recur each year

im not sure if this has been asked before if it has then please direct me to the appropriate post i have created posts for events that come up on fixed dates every year . so for example i have a ...
1
vote
0answers
14 views

How to display multiple custom fields with the same meta_key in an ascending order?

I am using query_posts to display a list of custom fields from some posts on my WordPress site. Each post has at least one custom field called showcase. In some cases, there are two showcase entries. ...
0
votes
0answers
15 views

Display custom type posts instead another custom type posts

I develope my WP site so I have 2 custom post types "cases" and "newcases". The "newcases" posts have new design and content. So I have more than 500 "cases" ...
0
votes
0answers
191 views

FacetWP paging custom wp_query

firstly the overview of what I'm trying to achieve. I'm building a resource center which lists out various custom post types and it's filterable/searchable thanks to FacetWP. Within this listing of ...
0
votes
1answer
16 views

Help with query_posts function

I have a paid theme that has the following function manually hard-coded. It pulls the 8 latest posts and displays them: global $do_not_duplicate; global $post; query_posts( array( 'posts_per_page'...
0
votes
0answers
15 views

“Post List” Loop containing other “Child Post List” loops causes pagination error ELEMENTOR

I am using a loop template to display posts in a custom template. The loop template contains another loop to display a list child posts. Child post list requires paginaion, but I am encountering a bug ...
0
votes
0answers
19 views

Wordpress primitive query returns = array

i am trying to primitive query form this wp_query: $query_v = array( 'post_type' => array('pro'), 'posts_per_page' => -1, 'orderby' => $count_visit, 'order' => 'ASC', ...
0
votes
1answer
19 views

Displaying all posts from other sites on the network on one site

I have a multi-site setup as follows Main Site has no posts Site A has 1 post A Site B has 1 post B Site C has 1 post C What I'm interested in is to be able to treat the main site as an aggregation ...
0
votes
0answers
12 views

How can I list all posts on a given day of the year (Month, Day, but _any_ year)?

Is there any way to show all the posts on a particular date for any year? WP has built-in support for a /yyyy/mm/dd/ path which will show an archive [I believe that's what it's called?] page for all ...
0
votes
1answer
26 views

Create a post automatically if search result has zero results

I'm developing a site where people can search phone number(s), the most complex part is that i want to create a post automatically when someone search for a specific number if that phone number yield ...
0
votes
1answer
22 views

Trying to list years (for a filter) but not all years display

I did an ajax filter to filter posts per years, however the filter isn't showing all items. Years are displayed in DESC order, but not all years appear I don't understand.... <?php $terms_year = ...
0
votes
0answers
14 views

Is there anyway I can call the year once?

Hi everyone I hope you have a great day, I was wondering if is there anyway I can call the year once?. I really don't know if its possible to call the date once cause mine keeps on repeating calling ...
0
votes
1answer
25 views

Getting post URL within custom content template

This should be such an easy thing but it's giving me so much headache. I created a content template called content-sticky.php. Added all the code there <article id="post-<?php the_ID(); ?&...
0
votes
0answers
48 views

custom post type get_posts() function not work

$orders = get_posts(array( 'post_type' => 'lp_order', )); foreach ($orders as $order) { // get all order data code } This the code I will try to learnpress plugin order post type front end ...
0
votes
0answers
21 views

How to fetch courses in all languages in WordPress?

I have a query which fetches English courses only. How can I fetch all the languages courses? I am using WooCommrce with LearnDash. public static function list_courses() { global $post; ...
1
vote
1answer
102 views

Can't search posts using WP_QUERY inside AJAX Function

WP_Query is used to get posts via simple arguments provided by it. WordPress provides an argument called 's' for search. It basically searches content of all posts and lists the ones with that string ...
0
votes
0answers
44 views

How to display only 1 post of many child-categories in the Parent Category page of Woocommerce

I am trying to display only one product of a child category in the page of parent category. If I use $query->set( 'posts_per_page', '1' ); it shows only only 1 post , which is near to what i want ...
2
votes
1answer
30 views

How do you query wordpress posts using a math formula between multiple meta field values?

The following scenario is entirely fictitious, but it illustrates what I'm working on perfectly. Imagine that you have a school syllabus set up in WordPress. The students can turn in assignments early ...
1
vote
1answer
296 views

Slow WP_query due to nested wp_query. Need Suggestions

I'm facing an issue of slow queries. As I'm not that familiar with the WP_query, I managed to solve my problem with nested wp_query. https://it.zoetalentsolutions.com/technology-provider/aws/ in the ...
0
votes
0answers
36 views

Filter search results by post_tag if exist

I want to get posts from search results using post_tag. for example If a user input in the search form "party". First, we search if "party" exists in post_tag and show all posts ...
0
votes
1answer
59 views

How do I change the default sort order of a custom column on the posts page?

I have a fancy custom column on the posts page in the WordPress admin. I have this column set up to be sortable. The first time that you click on the column header, the URL in the address bar changes ...
0
votes
1answer
129 views

custom post type and user post count shortcode

Hello i m a newbie in php and Wordpress development. I was struggling to get a user custom post count in my wordpress/buddypress site frontend. i m using this code: // add [author-post-count] ...
0
votes
1answer
81 views

pre_user_query vs pre_get_posts

I've used pre_user_query to edit the actual sql query and it works wonderfully. Now I'm trying to work with pre_get_posts and its not at all the same thing. I need to do an INNER JOIN.. In this ...

1
2 3 4 5
25