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

How to change category id on get_posts array

I am making a carousel for my AMP page, and I want to re-use the code, so I made it into a template, however, I am having the problem with changing ID on the array for category value, I would like to ...
0
votes
1answer
14 views

Drop down filter sort posts by latest, last 7 days and monthly

I am trying to use a drop down for users to select and show posts made latest, last 7 days and monthly. Currently I was able to find code to just sort by date in ASC and DESC order. <div id="...
0
votes
0answers
18 views

How do i POST to WordPress rest API from the same domain?

I created a custom rest API route - > http://mydomain/wp-json/v1/wp/custom/user now this POST request to this route works perfectly from a remote host. Some things change in my dev env and the JS ...
0
votes
1answer
30 views

How to get an array of pages ID by some page's slug and all its children pages in get_posts() function?

I have a custom function in my theme that creates a dynamic sitemap.xml file. For that I'm using $myVar = get_posts( array(...) ). In that array I need to exclude some pages. I want to exclude some ...
0
votes
0answers
11 views

how to get posts from dynamic category with wpbakery page builder post grid

I use Zephyer theme and I created a custom content template and I want to show posts from a dynamic category name . In default settings of wpbakery page builder post grid I can't set dynamic value ...
1
vote
0answers
20 views

A smarter way to display multiple loops inside a page template

I'm trying to make a page with multiple loops. I need each loop to display posts from a particular category. One category after another. At the moment I have the loop below displaying posts from a ...
0
votes
0answers
9 views

I want to get the data from WP-posts according to the Post_modified date. Please check my code and help me out

$args = array( 'post_status' => 'publish', 'post_type' => 'therapist', 'post_parent' => 0, array( 'meta_key' => 'post_modified', ...
0
votes
0answers
12 views

Wrap to First/Last when Linking to Previous/Next Post

I am trying to display two links, previous and next post in the current category. What I have so far works fine, but how do I make the next link to the first post when on the last post and vice-versa,...
0
votes
1answer
8 views

get_posts() not working with multiple statuses

I am running the following code: $posts = get_posts([ 'post_type' => ['my-type', 'another-type'], 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'title', ...
1
vote
1answer
21 views

How do I see the mysql query generated by get_posts( $args )?

I'm trying to use get_posts( $args ) to get some custom post types. Is there a way to see the mysql query generated by the get_posts function?
0
votes
0answers
15 views

How to get post from all custom post_type multisite to the main site with pagination ordered by date?

Currently this is my WordPress Multisite: Main site -Sub Site -Sub Site -Sub Site -Sub Site and this is the example code for getting all post from multisite : foreach( $blog_ids as $id ) { ...
0
votes
0answers
12 views

Get all posts by many custom post types

Question: I have many custom post types and i want to return all the posts by just a few of the post types: For example i have an array and was wondering if there was a way of passing this array to ...
0
votes
2answers
48 views

Recoverable Fatal Error - Object of class WP_Post could not be converted to string

Im using ACF and trying to show a post type title based on the current time. So I have my post type entry with start_time and end_time and my conditional is showing my div.onAir, but Im getting this ...
1
vote
0answers
15 views

How do I exclude recent post from recent post php widget

I have this code, and I tried adding in post__not_in as suggested by another post I found on this website, and it didn't break anything but didn't work either. I also tried different examples. Here's ...
1
vote
1answer
31 views

add active class based on permalink and url

i am facing a issue, on my wordpress site in left side i loaded post list with title and excerpt, and when you click on that content will get load on right side of page and its working fine but i ...
1
vote
0answers
13 views

Create a new query in function.php to filter blog posts

My goal is to filter blog posts (those which are requested in the blog page - Reading settings) depending on an expiration date, and then to change their category depending on a choosen future ...
0
votes
1answer
22 views

get_the_category return empty inside loop

I'm creating a custom template for my website and I'm currently using this code in order to loop to my multisite worpress and get the latest posts: global $post; global $wp_query; $subsites = ...
0
votes
1answer
29 views

Foreach Loop Of Post Types With Nested If Else If Not Completing Process

When my plugin is updated I am trying to write new values to the database. I am running through the post types and if it is Page Product or Post I want to place INDEX in to the DB. Else I want to ...
0
votes
1answer
45 views

Get latest posts from multisite

I've created a multisite on a local VM and installed my theme. Now I'm trying to get the latest posts from all the sites in order to display them ordered by last updated on homepage. From what I've ...
0
votes
1answer
44 views

get_posts return only first result

I try to get_posts like this: $sql = $wpdb->get_results( $querystrShop ); // Create array of product ID foreach ($sql as $prd) ...
0
votes
1answer
13 views

Modify default Related Posts Code to Custom Post Type

I'd like to modify this basic related posts code to my custom post type "Videos". Since I'm new to this stuff, can someone help me understand what I need to modify in this code so that it pull related ...
0
votes
1answer
46 views

get_posts( $args ) return empty data

I'm writing plugin for syncing prices of WooCommerce products with external source. So I want to get products with EAN (have meta data _wpm_gtin_code). Whaterver I pass to get_posts($args) I get empty ...
3
votes
3answers
97 views

Query posts ordering by title, but ignore " and special characters

I use following function to get my custom posts ordering by title $posts = get_posts( array( "orderby"=> "title", "order" => "ASC", "post_type" => "my-custom-post-...
0
votes
0answers
45 views

Related posts queries

Hey so I'm building a section that shows the related articles of a blog posts by doing a query with the post tags. I thought this section was working but suddently it started showing 5 posts instead ...
0
votes
1answer
39 views

How to Loop Through all Posts and Count Attachments using Get Media Attachments

I am working, on a code, where i need to loop Through all posts of a given author, and then for each post of that author, count the number of media attachments, the post has and then echo it. I am ...
1
vote
0answers
23 views

Weird orderby => post__in issue

I seem to have run into a sort of odd issue with WP_Query post__in I can't quite figure out. ANY help is appreciated! Goal/Progress so far: Overall I want to merge two arrays and use the merged ...
0
votes
1answer
18 views

Look up all posts by status or meta value - performance difference

Anyone know if there is likely a big performance difference to these two queries? get all posts by status = TRASH get all posts which have the meta key _delete_product and has a value of TRUE I will ...
0
votes
1answer
17 views

Return number of all custom posts type by author in all statuses

I'm using the code below to try to get a proper post count of all posts by a user but it's returning 0 for each user. function get_user_posts_count($user_id, $post_type) { $args['author'] = $...
0
votes
1answer
26 views

get_posts returns all posts

I am having some hard time figuring out why my get_posts function return all posts instead of specific ones. I have a post type called mall, in it a taxonomy called shop which have two terms Compi ...
0
votes
0answers
27 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
31 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
68 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
14 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
23 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
25 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
34 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
11 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
22 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
16 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
42 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
32 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
25 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' =&...
1
vote
1answer
753 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
49 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
196 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
102 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
122 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 ...

1
2 3 4 5
15