Questions tagged [get-posts]

get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 views

How to mark only one post as Featured post?

Am working on a blog page and I want to have a featured post as a banner. I have no idea how can I make only one post can be marked as the "Featured" so if another post is marked as "Featured" it ...
0
votes
1answer
26 views

Is there a way to extract a single post better than using get_posts()?

I have code like the following to extract data about a post: $args = array( 'post_type' => 'products', 'numberposts' => - 1, 'orderby' => 'meta_value', '...
1
vote
1answer
36 views

How to decrease the number of queries with get_posts and ACF?

In my index.php file, inside the classic WordPress loop, I had to query posts in order to retrieve the ones with a relationship value created with a custom field (managed with ACF plugin). I managed ...
0
votes
0answers
11 views

Filter post by category with pagination

Hi i want to display all categories on frontend as a checkbox and filter the blog post based on checkbox selected with pagination , any help please
0
votes
0answers
11 views

Display All Categories with Most Recent Posts and Featured Image

I am looking to build a custom archive page that automatically displays each category and the most recent 5 posts (featured image, date, and title) similar to https://bromabakery.com/recipes/. I was ...
1
vote
0answers
19 views

Get link which associated with a specific category and tag

We have 500+ post, 60+ tags, 3 categories. We want to give link on header part which have specific one category and one tag. For example: We have multiple post like: Blanket, Blender, Mixer, Wardrobe ...
0
votes
1answer
23 views

get_posts query results out of order but shows correct in php snippets plugin

I have a small plugin made for a custom site where a new word is to be picked via wp cron . The oldest (lowest ID #) custom post type should be selected in get_posts and returned. However, it always ...
0
votes
1answer
32 views

How can I show the author's latest post with title?

The following is my code: (klcom is my theme name) I just show the author by: name and description, I want to show the author's last 3 post with tile after each author, How can I code? Thanks <...
0
votes
0answers
9 views

How can I create a left join with posts that are associated with a post_tag?

How can I create a left join with posts that are associated with a post_tag? Example: cpt1: ID Course term_id 1 Course1 100 2 Course2 100 3 Course3 cpt2: ID User term_id 10 User1 100 11 User2 ...
0
votes
1answer
17 views

Override Blog pages show at most with get_posts

any idea how to override Blog pages show at most with get_posts? I tried with numberposts but it isn't working. $args1 = array( 'post_type' => 'wpcp-events' 'numberposts' => ...
1
vote
1answer
15 views

Stuck in Order by more then one

I want to orderby post by 2 custom fields and alphabetical here is my code 'meta_query' => array( array( 'relation' => 'AND', 'awards' => array( 'key' ...
0
votes
1answer
27 views

Check if searched number is within the post meta value

I wrote a function which search a list of properties by specify the number of guests. Each property have a specific number of guests, eg: 10, so if the user search as guests 5 the query should return ...
0
votes
0answers
10 views

In same page getting results for one category but not getting results for other category

Not getting result Benefits Section ============================--> <section id="services"> <div class="container"> <header class="section-header wow fadeInUp"> ...
0
votes
1answer
27 views

How to get meta key list efficiently?

I have this function to get the meta keys for all the post types. public function pgggo_custom_post_type_keylist() { //gets the list of post types $...
0
votes
0answers
19 views

Exclude admins from query get posts

We are using this code to see if the user has posted, however we wish to exclude admins. Currently if the role is admin, the function returns a post count. <?php $args = array( 'post_type' =&...
0
votes
1answer
207 views

Get the exact SQL query that get_posts() generated

I am working on a WordPress that someone else started and then disappeared. She created a few custom content types and variables using different plugins and I now want to access the data sets in the ...
0
votes
0answers
31 views

Querying nested ACF component fields

I have several components inside another component which I added to a custom field for a custom post type. Looking at the REST API, I see that my nested ACF components produce results like this: "...
0
votes
0answers
24 views

How can I render more than multiple posts on template-parts with post formats

I am trying to make a Wordpress theme. In my theme, there are multiple post formats and all are rendered on the index.php something like this website www.theoutline.com It has a 1st section with ...
0
votes
1answer
87 views

get_posts() from parent category only using a shortcode

I am trying to get_posts() from a category that has a subcategory within. To show an example please look at the image just below. So, as you can see. The parent and the children have posts inside. I ...
0
votes
0answers
61 views

How to Edit & Update meta_box values from Front-End user Form

I'm trying to Edit & Update meta_box values from front-End, Following codes are back-end. The problom is i'm fully confused with update post & update meta box. I hardly trying to get $package ...
0
votes
0answers
81 views

Array merging multiple get_posts throwing Undefined offset error

Good morning. I've been trying to create a related posts function. The broad idea being; the user can manually select related posts using an ACF relationship drag and drop interface, but if they don't ...
0
votes
1answer
22 views

How do I display an article using a WordPress custom field?

I want to display 3 articles with specific custom fields on the front page. The article needs to contain "featured" fields and the value is true. If the article does not exist, 3 random articles are ...
0
votes
1answer
24 views

SQL query generated by WP_Query is not the same what request echoes

given this code: $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'cat' => $cat, 'orderby' => 'date', 'order' => 'DESC', ...
0
votes
0answers
41 views

Remote Custom Post Type

I've got a remote source of data - customers and the items they've purchased - which resides on a different server and uses a system that's not Wordpress. But it's got a REST API I can call to obtain ...
0
votes
0answers
27 views

PaidMembershipsPro plugin's query filter not working for REST API calls

I have a custom REST API in WordPress that returns a list of posts using the get_posts function. I am using the PaidMembershipPro plugin, which typically filters the get_posts results according to ...
3
votes
2answers
303 views

Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?

The WP loop goes like this: if ( have_posts() ) { while ( have_posts() ) { the_post(); ... Why is it preferred over the following? foreach( (new WP_Query())->get_posts() as $post ) { .....
0
votes
0answers
29 views

How to query multiple post types and multiple post states [duplicate]

This following produces an empty array: $args2 = array( 'posts_per_page' => -1, 'paged' => 0, 'orderby' => 'post_date', 'order' => 'DESC', '...
1
vote
1answer
473 views

get_posts returning empty array

I am building a custom WordPress function/plugin that uses get_posts. The following code returns an empy array. I have included wp-load.php in my script. Is there something else I am missing? $...
0
votes
0answers
30 views

Add list with categories to choose from and save it as the category for the post

I have a solution for the fact that users can now add categories to their posts. Problem: they don't know which already exist and which do. Therefore, I'd like to go to a route where users can choose (...
0
votes
1answer
15 views

Inserting post content into pages when using custom taxonomies

I am inserting a snippet of text into posts when posts have a certain taxonomy. I want this text to be editable by WP users n the admin area. The following doesn't seem to want to do anything for me,...
0
votes
0answers
262 views

how to get wp_query posts only first letter of alphabet A?

I want to get all the data by wp_query only the first letter of title specific alphabet 'A'. My code will be like: $the_query = new WP_Query( array( 'posts_per_page'=>10, ...
0
votes
1answer
35 views

Update all WordPress posts's title and content then display them in a table

I am trying to update all the WP post title and content then show the just updated post to a table. I am using the following code but it does not work: $args = array( 'post_type' => 'post', '...
0
votes
2answers
266 views

How to get_posts where 'menu_order' is more than 0/zero?

Is it possible to get posts where menu_order is more than 0? I have tried this argument when I get_posts() but it doesn't have any effect at all: 'meta_query' => array( 'key' => '...
4
votes
1answer
71 views

Is it possible to select against a post's parent's fields with WP_Query?

I'd like to query post revisions using WP_Query for display on an admin page, and I want to include pagination parameters. I have two constraints: I would like to only retrieve revisions for ...
1
vote
1answer
272 views

get_next_post() and get_previous_post() return wrong posts

I’ve been trying to retrieve the next and previous post in one of my Wordpress templates. Please note that I want to get the full post object instead of just the pre-formatted links to the posts. The ...
0
votes
0answers
11 views

Display random posts, favoring posts published close to todays date regardless of year

I would like my start page to display random posts, but put posts published close to today’s date first and posts published far from today’s date last - but regardless of what year the posts were ...
0
votes
0answers
50 views

get_post Question

We have a custom post that displays a main post and several child posts. The main parent post displays a table with a summery of specs for the product. at the bottom of the table we have a link to a ...
0
votes
1answer
76 views

How to get posts without author?

I am looking for a way to get all posts without author. They were inserted with post_author = 0; But the following line returns all posts instead of the posts with no/null author get_posts( array('...
0
votes
0answers
46 views

get_next_post() not working with future post status

I'm using in single post template simple navigation below the post content: $next_post = get_next_post(); if($next_post) { $next_title = strip_tags(str_replace('"', '', $next_post->...
0
votes
2answers
43 views

Best choice for multiple loop in page?

My home page include five loop. currently i use wp_query but is it optimized ? best choice with get_posts ? my code looks like that // First loop $args_dogs = array( 'post_type' => ...
4
votes
1answer
84 views

How to know if get_posts() failed?

So I see that get_posts() function return an array of posts. If there are posts, it returns an array of posts. If there are no posts it returns an empty array(). If there are posts, but the querying ...
0
votes
1answer
76 views

How to count posts with specific arguments

I'm wondering how I can request the amount of posts by passing certain arguments (you could see this as part of a "query"). See the example below. $args = [ "numberposts" => -1, "...
1
vote
1answer
31 views

Function to check if author has posted within the last x days

Is is possible to check whether an author has posted in the last X days? I am currently using this function to determine whether he has posted at all. $args = array( 'post_type' => '...
1
vote
1answer
73 views

`get_posts()` ignore my custom post

I have a Custom Post Type: function thfo_register_cantine() { $labels = array( 'name' => 'Cantines', 'singular_name' => 'Cantine', 'menu_name' ...
0
votes
1answer
157 views

Is it possible to use array_walk() to append terms to an array of posts?

I'm creating a masonry post grid of animals. I plan to filter the the visible posts by toggling classes. The classes would in turn would be the post's. I'm using an MVC theme and would like to get ...
0
votes
1answer
16 views

Extracting the permalink from a post instance

I'm exporting some posts from a WordPress site. One of the attributes of a post instance derived from $posts = get_posts(); is guid .. $post->guid which shows how to find the original post. ...
0
votes
2answers
24 views

How to give classname to post if post has no content?

I want to give a post a classname on the homepage (index) if the post on the single page has no content. So when the post itself exists but there is no content, I want to give a classname to that ...
1
vote
1answer
33 views

Insert Content In Between Post Feed

I am a bit lost and looking for guidance. I have a homepage that lists blog posts. However after every 3rd post (we'll call this the "Main Feed") I want to add a section in between that looks ...
0
votes
2answers
327 views

Query a custom taxonomy in a function to create an csv file

I a problem with getting the query for custom taxonomy to work in this function. The $filter is filled with data but the get_posts() does not use it? The query works without the tax_query and there ...
0
votes
1answer
278 views

In a multisite, how can I get posts from one site and display their permalinks in another site?

I have a WordPress multisite with one main site and four sub-sites. In a PHP template on my main site, I would like to get the posts from one of the sub-sites and print the permalinks to the page. ...