Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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
0answers
22 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
26 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
16 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' => '...
5
votes
1answer
41 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
78 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
27 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
12 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
25 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
30 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
66 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
37 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
21 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
66 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
30 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
15 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
17 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
131 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
45 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
37 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
46 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
64 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
40 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
92 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
34 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
179 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
24 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
123 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
13 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
270 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
579 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
240 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
356 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
53 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
531 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
94 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
57 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
439 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 ...
4
votes
1answer
60 views

Is the first item returned by get_posts() always the latest post?

I want to retrieve the modification date of the latest post. To do this, first I get the latest post: $latest_post = get_posts()[0]; Can I be certain that the returned object is always the latest ...
1
vote
1answer
15 views

Simple Filter between multiple taxonomys

I create 2 dropdowns one for each category & tag and filtering posts successfully. After that i create a custom taxonomy cat and try to filter post between all three dropdowns. But dropdown for ...
0
votes
1answer
12 views

How to apply a function to a metadata value before launch a WP Query?

I have these WP_Query arguments: $args = array( 'post_type' => 'my_post_type', 'order' => 'ASC', 'meta_key' => 'date', 'orderby' => 'meta_value_num' ); ...
0
votes
0answers
74 views

how to display active, upcoming and past event with featured listing with pagination

I have a code that work fine for Active Events Page, Upcoming Event Page & Past Event Page with a event_start_date later than today. What I want is? A : To show Active, Upcoming, Past event post ...
0
votes
1answer
146 views

Fill the exclude array() in get_posts()

I'm using this code to populate the dropdown menu in a meta box. $parents = get_posts( array( 'post_type' => 'jhk_story', 'orderby' => 'ID', ...
0
votes
0answers
19 views

Posts page listing pages as well

I have set my Posts to output on a specific page by selecting that page as the posts page in the settings->reading tab. That page is outputting content using my index.php template like I wanted. ...
0
votes
2answers
241 views

Query post with meta value in set of values

I am trying to build a query that returns all posts, with a meta value that exists in a set of values. My posts have a meta key called Asin_unique and I want to find all posts, that have the value ...
0
votes
0answers
37 views

Using the_content() causes the white screen of death

I have a custom post type for creating popups. I have a loop where I display all the popups and it all works fine, until I try get the content using the_content(); the_title(), the_ID() etc., all ...