Questions tagged [get-posts]

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

0
votes
1answer
16 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
24 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
18 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
221 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
28 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
162 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
14 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
63 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
27 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
45 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
50 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 ...
0
votes
1answer
123 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
10 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
29 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
15 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
29 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
34 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
69 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
43 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
26 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
69 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
39 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
0answers
15 views

Creating a menu item that calls one random custom post type by category

I hope someone can help me solve this. I am current building locally on WAMP and I have some code on my website that will call a random video post by setting the menu url to.. http://192.168.0.73/pgv/...
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
21 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
23 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
0answers
23 views

List attachments by taxonomy

Trying to list two columns of attachments (pdfs), each with taxonomies (tags) of either "sub" or "ins". I almost have it but no quite: <?php $terms_array = array( 'taxonomy' => '...
0
votes
2answers
178 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
85 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. ...
0
votes
1answer
38 views

How to add post page pagination to template part?

How can I get this page to display the post page pagination? I'm using a custom blog template with a get_template_part. https://www.nowitconnects.com/blog/ <?php /** * Template part for ...
0
votes
1answer
65 views

get_posts() not working when accessing with a custom user role

I've stumbled across something that I can't seem to find any documentation on regarding WP 'get_posts' function. I've got a web application that has multiple custom post-types and multiple custom ...
0
votes
2answers
71 views

Get all posts which was posted on X Days WordPress

I want to get all post which was posted on X Days, I don't want 7 days old post or 1 Month old posts, Because it will return all posts which will be older 7 days or one month. Like Today is 15 SEP, I ...
0
votes
1answer
51 views

custom hierarchical taxonomy and custom post type list contains surplus posts

I wish to list custom taxonomy terms as titles and custom posts as lists under titles: Basics List item1 List item2 Movies List item3 Images List item4 However, custom taxonomy is HIERARCHICAL ...
0
votes
1answer
125 views

get_posts custom field

This is a silly question, but I can't find the proper way to ask it to google. so, sorry if this is a repetitive question. I give a custom field with a checked that the user can check if he want ...
1
vote
0answers
35 views

Query Multiple Custom Posts by Custom Fields

We have 3 custom post types and we need to query all 3 and join them in order the get that data to build up a complete list of films at a venue. Tables are as follows, with there unique ID's. The ...
0
votes
1answer
258 views

Using get_posts to get posts based on a checkbox value with Advanced Custom Fields

I have a custom post type, "Jobs". These jobs have an ACF checkbox field, "city". "Jobs" can have more than one "city," so the jobs returned have meta values look something like this: [city] => ...
0
votes
0answers
25 views

Filtering custom posts by custom taxonomy and user role using get_posts

I'm trying to filter my custom posts in a get_posts loop by first checking if the current user has a particular role and then filtering by a custom taxonomy term. However, I can't seem to get the ...
0
votes
0answers
159 views

Gravity Form After Submission Update Custom Post Type Taxonomy Terms

I am creating an online proposal system using a custom post type called 'proposal'. For the approval form, I am simply using a Gravity Form which then emails me if the client approves the proposal. ...
1
vote
1answer
34 views

Are there sub-systems in WordPress that would employ data structures beyond CPT that a `get_posts` won't be able to catch?

I'm building functionality to remove posts that have a certain key/value term pair. All fine and dandy, I can run a query like this: $posts = get_posts([ 'post_type' => 'any', '...
0
votes
0answers
14 views

How to get post data of Quiz Cat Plugin

I want to get quiz data of "Quiz Cat" plugin, I tried researching in the documentation about the code in plugin. But did not get anything regarding it. I know how to get post data of blog posts as ...
0
votes
1answer
358 views

get_posts - get all posts by array of author

I have a case like below. Confused how to use the wpQuery to achieve this This is for a single user. Not sure how can i pass the array. global $current_user; get_currentuserinfo(); ...
1
vote
2answers
816 views

How to get post from all Blog Multisite to the Main Site?

How do I display all posts from multisite to the main site? Please help me. thanks.
1
vote
1answer
283 views

How to filter get_post with ACF by a checkbox field?

So, I have a custom content type called "team" where I have an ACF field attached called "external" which is a checkbox. I am currently getting all the posts by passing the following arguments array ...
0
votes
1answer
514 views

Quickest way to get last or oldest post date - WP Query

I know how to get the last or oldest post data using following code $posts = get_posts(array( 'post_type' => 'post', 'order_by' => 'publish_date', 'order' => 'ASC' )); And then I will ...
2
votes
1answer
62 views

How to get previous 10 days post from a specific date - WP Query

I want to know how to get previous 10 days post from a specific date, as I know that it can be done from current date as below $args = array( 'post_type' => 'post', 'date_query' => ...
0
votes
2answers
723 views

get the_content by ID and save the result to one array

I try this: <?php function get_ct($id){ $ct = apply_filters('the_content', get_post_field('post_content', $id)); return $ct; } $arr = array('post_content' => get_ct(...
0
votes
0answers
128 views

List all custom taxonomy terms related to another taxonomy

I want to list all custom taxonomy terms related to another taxonomy. For example the following case: Custom Post Type: Car Taxonomy 1: Brand ->Terms: Audi, Bentley, BMW, Bugatti, ... Taxonomy 2: ...
0
votes
1answer
61 views

Portfolio list view after clicking back button

how would it be possible to get back to the same portfolio listing page, after the clicking browser back button from single portfolio item? Now it goes back to the first page of portfolio listing. ...
0
votes
0answers
576 views

REST API Working for GET but not for POST?

I am trying to create a post through the REST API. I am able to access the API by getting the existing posts, as per the screenshot below: However, when I try to do a similar request to create a new ...