Stack Exchange Network

Stack Exchange network consists of 174 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.

4
votes
2answers
49 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
29 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
20 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
63 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
21 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
21 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
11 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
69 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
29 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
35 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
32 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
56 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
29 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
52 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
32 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
94 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
23 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
105 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
11 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
157 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
383 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
152 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
227 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
45 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
328 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
84 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
50 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
325 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
55 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
14 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
11 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
63 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
86 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
148 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
35 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 ...
0
votes
0answers
45 views

Order posts by specific post IDs

I have the following code: $viewed_products = [3358, 3296, 3929, 3368]; $query_args = array( 'posts_per_page' => 4, 'no_found_rows' => 1, 'post_status' => 'publish', '...
2
votes
1answer
97 views

How to retrieve a value from get_posts()? [closed]

I'm just trying to retrieve a value of 'title_name' from get_posts and gets the error "cannot use object of type WP_post as array..." The reason I'm not using have_posts/the_posts is because I want to ...
1
vote
1answer
552 views

Get posts by meta value with date

I have a post type called "agenda" and one of its meta value is the date of the event. How can I get the posts of the current year based on the meta value? I tried this args above but it doesn't ...
2
votes
1answer
74 views

get_posts gives different result than wpdb->get_results

I ran into something that has me completely stumped. For a cron job I need to retrieve which users are 'marked' as VIP and then retrieve the posts from these VIP users. global $wpdb; $...
2
votes
0answers
69 views

Adding multiple post queries with parent and children to page - Best Way

So I am interested in allowing a custom menu to show "in three places: Menu area, Homepage body, and footer" based on the posttype "page" table list or parent and children entries and not using the WP ...
0
votes
2answers
50 views

Custom Category widget

I have a custom code in sidebar.php that shows all my categories and number of posts+custom posts. The code is working fine but, since I copied/pasted and modified various other codes from ...
0
votes
1answer
119 views

Posts query according to meta box date

I'm struggling to get a working solution with wp_query for Event management, Currently post order by event start date & time work well. Now I want some custom settings. Have two meta boxes ...
0
votes
1answer
165 views

How to get only one category of custom post type?

I get all post successfully of CPT which are Order by meta_key value Date. Code is below $today = date("Y/m/j"); query_posts(array( 'post_type' => 'event', 'posts_per_page' => 10, 'meta_key' =&...
-1
votes
1answer
35 views

wordpress show category link instead of post link [closed]

I'm running WordPress on localhost using XAMPP. I have a few posts and added them to a specific category (for example cat1 and cat2). I've added the categories to the menu, and when I click on the ...
1
vote
2answers
49 views

show first 3 thumbnails of posts in different sizes [closed]

i want to make a little Header with the 3 recent thumbnails in different sizes and start my loop with the 4th recent posts, can someone give me a function for that please? please no widgets i want to ...