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

Unexpected warning message to my WordPress posts which group and listed out by year

I have my WordPress posts looped and listed out by year successfully. However, I am unsure why I still received a warning message. Warning: Undefined variable $year_check Below are the codes that I ...
Danc Chan's user avatar
3 votes
1 answer
70 views

Force new posts to the top of query loop

I have a query where the posts is ordered by title. I am trying to filter into the (main) query in order to have the newest (created in the last 14 days) on top of the loop. Below the newly created ...
pstidsen's user avatar
0 votes
0 answers
21 views

Get 404 when using url parameters to filter custom post type archive page created with wp bakery post grid

I created a custom post type named tutors_quiz than I create custom taxonomy named tutor-quiz-tag. I create an archive page with wp bakery post grid. screenshot https://prnt.sc/VdvDp9-ekt3c Now I want ...
srana's user avatar
  • 1
0 votes
1 answer
278 views

get_the_ID() retrieves same ID on Gutenberg's Query Loop

I'm using Gutenberg editor and I want to add a shortcode (using XYZ PHP Code) that uses the post id to retrieve certain ACF value. I'm editing the home page where the last blog posts are shown, but I ...
Alvaro's user avatar
  • 121
0 votes
1 answer
30 views

get posts from Rest Api by meta_key/meta_value not working

I have a function that fetches all the latest posts which works fine. But i wish to fetch only the posts that have a specific value from a custom option. But adding the meta_key/meta_value does not ...
Christophe's user avatar
0 votes
2 answers
87 views

Exclude first post from wp query

I am building a WordPress website and I want to show post in it. But the problem is that, I want to exclude the first post in query. I have not much knowledge of PHP. So please help me to de this. ...
Ahmed Muneeb's user avatar
0 votes
1 answer
34 views

new WP_Query with order args – no more distinction between categories

I try to change the post order on all of my category/archive pages from the WP standard to having them sorted by their modified date. I modified a part of the loop.php from my theme (derived from ...
Frank Wagner's user avatar
0 votes
1 answer
134 views

How to change url of posts?

I want to show my posts url like "domain.in/blogs/blogname" . for only the posts not for the pages. how can i make it like that
spidy223's user avatar
0 votes
1 answer
34 views

How do I exclude the current post from the upcoming post query

Summary: I have a page template with 3 queries. Current Exhibition Upcoming Exhibition Past Exhibition The dates are custom fields. The problem I'm having is, how do I dynamically exclude the ...
Chris Brennan's user avatar
0 votes
0 answers
60 views

/page/2/ redirect to 404

I make a filter form in the category page and get parameters with get_query_var, my problem is in the Pagination when the user filters a parameter and wants to go to page 2, it redirects it to 404 ...
Heisenberg's user avatar
0 votes
0 answers
60 views

How to get recent one post from each category on home page?

I am trying to display one post from each category. I currently have five categories, with two parents and three children. Animal, -Cat, and Home —Water Filter -Kitchen. Code have error if any recent ...
015ra's user avatar
  • 9
0 votes
0 answers
22 views

Trying to set up a range filter for related custom post types

I have set up two CPTs, "Property" and "Suite". Each Property has a number of Suites assigned to it via an ACF bidirectional relationship.  Each suite has a set size (in square ...
Jon Timms's user avatar
0 votes
1 answer
84 views

Count words for all posts by all authors

So I got this code from another query and it works for one single post. However, I want to show the total words of all the published posts by all authors. How do I modify this or is there a wp ...
Elaine Byene's user avatar
0 votes
1 answer
367 views

Display ACF object field data using Elementor Custom Query

Hello i'm working on a website using elementor pro + ACF. I have create a custom post type (CPT1) with ACF object field that take another CPT2 as values. I would like to display on my CPT1 page all ...
AKEAmazan's user avatar
0 votes
0 answers
107 views

Optimising WP_Query with ACF Fields

I am wondering if it's still possible to optimise the WP_Query or also if there's another way of doing it. I have the post type and a custom post type called case-study which gets displayed on the ...
Erick T's user avatar
0 votes
1 answer
23 views

change the default order of posts only for specific categories

I want to change the default ordering for posts, to last modified date, but only for certain categories pages (when visiting certain category pages) I have this function code, which is working, but I ...
vyperlook's user avatar
  • 167
0 votes
0 answers
625 views

Elementor posts custom query based on tag [closed]

How can I filter the Elementor Posts widget with a custom php query that returns posts with a specific tag attached? I want to do something similar to this: function my_query_by_post_types( $query ) { ...
ChristosDg's user avatar
0 votes
0 answers
220 views

Custom Query: Multiple CPTs and a taxonomy filter

I want to create a post feed that displays the following: ALL posts in the CPT 'custom_post_type_1' Any 'post's in the category 'speakers' So far, I have this filter which displays all posts in '...
srack's user avatar
  • 1
0 votes
0 answers
194 views

Query post and sort by custom value calculated with custom field on cpt

I shall made a query post ad I have some issue to sort the posts. I have multiple custom fields that calculated in php (with some operators) a final value for each posts - I call it $price. These ...
James's user avatar
  • 1
0 votes
1 answer
90 views

How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]

I am using ACF Pro to make a relationship between two custom post types. One CPT is a thing and the other is a Container of Things. I need to solve the issue of things within a container of things ...
Jordan W.'s user avatar
0 votes
0 answers
33 views

WP query_posts group by meta field related

Hello Guys i am trying to customize a wordpress theme and am getting this is How it queries All Posts with episodes post_type. My Question Is. this Post type is related to another post_type which is ...
Tristan Morris's user avatar
0 votes
1 answer
86 views

Conditional operator OR not working with custom fields

OR operator is not working for both conditions, only check first value if true then code executed and if first is false then not check 2nd condition and return else output. I also try with LIKE ...
Puneet's user avatar
  • 37
0 votes
1 answer
140 views

complex get_posts() query to select child pages

I have pages on 2 levels under the main deparments page like below. Departments --Department 1 -----Course 1 -----Course 2 --Department 1 -----Course 3 -----Course 4 --Department 3 --Department ...
LeeTee's user avatar
  • 31
1 vote
0 answers
25 views

How can I create 'future' and 'past' parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?

add_filter( 'rest_events_query', 'filter_events_by_date_field', 999, 2 ); function filter_events_by_date_field( $args, $request ) { if ( ! isset( $request['filter_date'] ) ) { return $args; } $...
Abi's user avatar
  • 11
0 votes
0 answers
105 views

search.php to search only the post title

I'm trying to rewrite my search.php to search only for the post titles because I have a ton of posts published to my site (around 400k), which slows down the search speed to about 20s per search. <?...
Dardan Asllani's user avatar
0 votes
1 answer
347 views

Change the destination of the URLs in post.php

The post.php screen lists posts vertically in the admin area [and other post types]. Each item's post_title is a hyperlink, directly above some inline choices. Both the title link, and the "Edit&...
John Dee's user avatar
  • 503
0 votes
0 answers
48 views

Hot to check if new posts have been published since page load and notify online users?

I want to show a div notifying online users that there are new posts since they have accessed the page, in the index and also if new posts have been added in the category or tag they are browsing. I ...
Carlos B's user avatar
0 votes
1 answer
85 views

Include current post into loop

I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/ But I also need to include current ...
Teymur Abbasov's user avatar
0 votes
1 answer
314 views

Filter products on category AND tag

I want to be able to filter products based on category AND tag, as well as sub category AND tag. From my research I heard that I must write some kind of rewrite rule in functions.php for this to be ...
Fernando Redondo's user avatar
0 votes
0 answers
152 views

Sticky posts limit query and pagination for a custom post type

I would like to display 9 posts per page. But, when I have a sticky post, I would like it to be integrated in the 9 posts in the query. And, then, for the second page, I continue to have the next 9 ...
Gpi's user avatar
  • 101
1 vote
0 answers
51 views

Serve specific "template" page at any URL that ends in its slug

Still new to WordPress, so please go easy on me. Goal: Prevent users of a specific role from viewing other custom post types made by users of same role. Intended solution: Modify the URL and redirect ...
Ryan Cochran's user avatar
0 votes
2 answers
129 views

Move position in post list for a custom checkbox column

I have made checkboxes to every post in post list. Question: How can I change the the position for the new column. Now it`s at the right side of the post list. After "Date". How can I move ...
bjovaar's user avatar
  • 21
0 votes
0 answers
62 views

Change pure SQL database query to WordPress post query?

I am trying to query posts that are nearby a given (lat/long) location. I have found this working SQL query, but this won't provide me flexibility to alter the queried later on, since I am not really ...
RobbTe's user avatar
  • 230
-1 votes
1 answer
319 views

Wordpress pagination returns the same posts

I did search the other posts here related to this problem, and tried all of them in my case, but I can't seem to make it work (probably because I don't know enough code) Can you please help me with ...
vyperlook's user avatar
  • 167
0 votes
0 answers
50 views

Counting post and changing roles in mysql database. Query not code

Hello I'm struggling to find an answer talking specifically about counting post and changing roles but on mysql language not php in the wordpress source. I'm not creating a plugin neither I want to ...
gallo2000sv's user avatar
0 votes
1 answer
82 views

Why does my WP_Query pagination on a custom page.php only loads the homepage?

What I am looking to do: Setup WP_Query pagination in a custom php template file with a custom WP_Query query (It's not originally mine, I'm just fixing it). The file loops through posts (category &...
Lisa's user avatar
  • 3
0 votes
0 answers
47 views

Query post ordered by meta value that show first post that contained a tag

I have a query post for my CPT 'listing' that order posts by value of price contained on meta key. Now I'd like to add the possibility to show in the loop first posts that has a specific tag (o ...
Giulio's user avatar
  • 51
0 votes
0 answers
103 views

Facing problem with tax_query results

I need to get search results for posts on the basis of post-category(must) and posts-tags(optional). The process is like: search for a string e.g. "bananas" the category is always static ...
Majid A.'s user avatar
0 votes
0 answers
80 views

How do i create a custom post query when the meta value is an array?

A number of properties have been imported from an external API and saved into a custom post type called 'Properties'. I want to filter these properties by the city they are located in, however it is ...
Zeus7's user avatar
  • 1
0 votes
0 answers
531 views

Custom post type archive page filters

What is the proper way to filter my custom post type archive page by my custom taxonomies? When i go to archive page(archive-recipies.php), fetch me all the post under the custom post type. In this ...
Tsourou Nas's user avatar
0 votes
1 answer
102 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' =&...
Eli Nathan's user avatar
0 votes
1 answer
154 views

Get a Post Loop based on Logged in User information into a Shortcode

I have a follower button on users profiles where users can follow other users. I have a page template that shows all posts by users the currently logged in user follows. I would like to create a ...
RobH's user avatar
  • 7
0 votes
1 answer
104 views

How to obtain the recent posts without their content in an efficient way?

It would be great to make a single DB request but I don't know how to do that either. I have this code and it works but I want to change it to be more efficient: $cs = get_categories(array( '...
silviubogan's user avatar
1 vote
0 answers
44 views

Set multiple Post Terms in same Taxonomy

I'm having a hard time trying to figure out this problem. I have looked at various StackExchange threads but nothing seems to work. Long story short. I have a custom table that updates every day which ...
Giacomo Gaglione's user avatar
0 votes
0 answers
245 views

WordPress create custom XML RSS feed template

I am trying to create a custom XML RSS feed. However, my code is not quite working as expected. Here is what I have done: In functions.php I have created the feed called "top": add_action('...
TurboTobias's user avatar
0 votes
0 answers
102 views

Global $post returns 2 objects for my shortcode

I made a shortcode, it does most of what I need it to do. Except for a filter I need the post id of the page the shortcode is placed. (to get some linked custom field values) And I can't expect the ...
marty90's user avatar
  • 11
5 votes
1 answer
3k views

WP 5.8 "Query Loop" block: where to place custom query?

In the recent wordpress.org article outlining the new Query Loop block, it says the "Inherit query from template" option allows you to "customize the query that the loop relies upon ... ...
Rickmakeitquick's user avatar
1 vote
1 answer
641 views

Query with a meta value inside a given range

Quick question: I would like to retrieve some pages/posts with a meta value inside a range, eg) $min<$meta_value<$max for ordinary $meta_value there was a way to get pages/posts like this: $args ...
Martin Spinoza's user avatar
0 votes
1 answer
341 views

Show posts from two specific category in WP_Query

I've two category employee and full-time. If a post publish in both (employee and full-time) category then the post will show in his specific section. If post has only employee category, not full-time ...
user avatar
1 vote
1 answer
939 views

Filling custom post type posts from a rest api

I have been trying different wordpress intermediate challenges, I came across one today that brought up a question I had no idea how to resolve it requires displaying data from a rest api however the ...
Azurry's user avatar
  • 111

1
2 3 4 5
25