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
1
vote
1answer
331 views

get_children() not working properly – Only on one post?

Client wants to show how many images await the reader in a post. I say: easy peazy. Now I realize: I lied. The system only uses galleries, even for single pictures. $images = get_children(array( ...
0
votes
1answer
2k views

get the post_date of ID

How can I get the post date of ID? this is my code $id = "13"; //wp_posts ID get_post_date("Y-m-d H:i:s", $id) //is there something like this in wordpress? I dont like to create a custom query if ...
0
votes
1answer
2k views

How to find out what “Blog pages show at most” is set to [duplicate]

Under Settings > Reading, there is a field called Blog pages show at most __ posts. Since all of my queries are based off of the main query, I need to find out what's stored in that field. How would ...
0
votes
1answer
1k views

Displaying POST content with HTML tags and all

The following code allows me to display the post TITLE and content fine, but the content is not displaying as I see it on POST EDITOR. Here's the webpage where the PHP is rendered: http://queridas....
0
votes
1answer
232 views

How to Group While Loop “Results” of wp_query?

I have the results from a query and they're fine, I am getting post via tags. I want to sort the result in WHILE LOOP. Here's the code $tags = wp_get_post_tags($post->ID); if ($tags) { $...
0
votes
2answers
229 views

get_posts only getting most recent product

I had a website built on Woocommerce for me, but no longer have access to the Developer. I'm not a programmer so anything beyond CSS changes gives me quite a bit of problems. There is a piece of code ...
0
votes
1answer
37 views

Custom Articles page only showing a limited number of posts per page

I have been developing my own theme for my website over at http://haydenbjyoung.co.uk called FluX, and if you click on the 'Articles' link in the navbar, it only shows 5 articles, out of around 20 I ...
0
votes
2answers
29 views

Get Posts from Custom Meta Query

I want to query posts using the get_posts() function and am having trouble getting the query to work properly. The $country, $us_state, $ca_state, $mx_state values will be pulled from a Gravity Forms ...
0
votes
1answer
27 views

get the headlines of the authors' last post

I want to list my authors with the title of their last post. ı want to sample sort user1, title1, date=19.10.2017 > user2, title2, date=17.10.2017 > user3, title3, date=15.10.2017 <?php global $...
0
votes
1answer
54 views

Random posts from a pool of posts

Right now my site shows 3 random posts at the end of my single page articles. Here is the code I use and it works (with comments): <?php $rand_posts = ...
0
votes
2answers
22 views

Get posts base on category ratio of more then two categories

Is there a way to doing this easily like There are three or may be more I want to display the posts of above categories like Bring posts from categories From Category A: 20% OR 2 From Category B: ...
0
votes
0answers
31 views

Zero posts returned with get_posts() on edit.php, but posts are returned on post.php

I have a function which returns all posts of a certain post type, simplified here: public static function getFoos() { $output = array(); $args = array( 'posts_per_page' => -1, ...
0
votes
0answers
181 views

get_posts query caching?

I'm using get_posts outside of the Wordpress theme and it's pulling up posts which used to have meta "featured_user" = on and none of the new post which has meta "featured_user" = on. This behavior ...
1
vote
2answers
369 views

How to update all posts but the current one (post__not_in not working?)

I'm trying to unpublish (set post_status to draft) all posts when a new one (with specific conditions that don't really matter right now) is published. Here's what I currently have: function ...
0
votes
1answer
25 views

How do I get posts where image is larger than…?

How do I get only posts where there's featured image's dimensions is larger than for example 1000x500px? Want for example the two latest posts where there's featured images is that big. So, not just ...
0
votes
1answer
238 views

get_posts() interrupt because of filter

There is a filter on my list-view page of my custom post type (works) add_action( 'pre_get_posts', array($this, 'exclude_category') ); public function exclude_category( $query){ if( ...
1
vote
2answers
109 views

Posts not showing in correct Alphabetical or ID order when using get_posts / orderby but only on production server

I have a page that lists some custom posts and the they are not showing in the correct Alphabetical order. As a test I have also tried listing them in order of there Ids and that does not appear in ...
0
votes
0answers
694 views

Get posts with any value in attribute

Hello I am trying to do this query that extract woocommerce products with 3 attributes (Collezione, Finitura, Pietre). But we can have none,1,2 or 3 filters set, so I wanna ask you which value I have ...
0
votes
2answers
933 views

Woocommerce: order posts by meta key

I have the following args array { "ordreby":"meta_value_num", "meta_key":"_price", "posts_per_page":10, "offset":0, "post_type":"product", "post_status":"publish", "order":"asc"...
0
votes
1answer
227 views

WP_Query to get posts in a specific tag or has post_format

I want to get the posts for two different taxonomies. I want to list posts only if those posts either have tag longform or the post_format is type link. I have tried the below code, but it's not ...
0
votes
3answers
62 views

Counting posts with argument without retrieving the posts

I have a quite extensive database, 30000+ items, and using this: $args = array( 'posts_per_page' => -1, 'post_type' => 'books', 's' => $s ); $post_counts = ...
1
vote
1answer
487 views

Shortcode for display posts on home page show only one post

Need to display 3 posts. I created this code: add_shortcode('projects', 'projects_shortcode'); function projects_shortcode($atts, $content){ extract(shortcode_atts(array( 'post_type' => '...
-1
votes
1answer
49 views

Display posts from another page on home page in wp-editor

I use this code for display posts from another page on home page in front-page.php template: <?php $args = array( 'post_type' => array('project') ); $the_query = new WP_Query( $args ); ?>...
0
votes
1answer
182 views

Why does 'meta_key' return an empty array in get_pages

Very simply, get_pages() will return all pages. I want to get all pages that have a custom field key called 'basePrice', regardless of the value. But when I try to use get_pages(array( '...
1
vote
1answer
107 views

How can I get the homepage from the loop?

From the get Get_Pages documentation (https://codex.wordpress.org/Function_Reference/get_pages) I understand it should look more or less like this: <?php $args = array( 'post_type' => '...
2
votes
2answers
841 views

data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}

WordPress Devs. I am new to WordPress and Web development. So far WordPress Rest API v2 works well. I was writing a custom API/route/endpoint for my project using the following function. get_post($...
0
votes
2answers
2k views

get_posts custom paging

I created a search for my site using attachments. Each attachment is in category "Pictures", so my search form looks like: <form method="get" id="searchform" action="<?php bloginfo('url'); ?>...
0
votes
2answers
92 views

Media Library Category Exclude Tree

I have some code that returns the latest 5 images from the WordPress Media Library: <?php $excluded = array(1,35,37); $args = array( 'post_type' => 'attachment', '...
0
votes
0answers
523 views

$product->ID in has_term() not working, but manually inputting the ID works, why?

I have this code which I am using to loop through all products, then it should print the $current_product array if a product has term 'composite' from the 'product_type' taxonomy - it doesn't. BUT if ...
4
votes
4answers
4k views

get_template_part in for loop

Due to the setup of my template (and layout), I need to be able to place 4 different posts in 4 different divs. For example, my structure would be like this <div>Post 1</div> <div> ...
0
votes
1answer
578 views

Category_in return empty

I have the following code to obtain products within a category $product = new WC_Product($id); $categories = $product->get_category_ids(); //return array(21) $args = array(); $args["...
1
vote
0answers
405 views

Open post-content in archive page in a Modal box with bootstrap

on my archive page, i m trying to display the post content in a modal box ( using bootstrap). I manage only to display the first post in a modal box, nothing happen if I click on the other posts from ...
0
votes
1answer
201 views

WP_User_Query and user posts

I queried a list of users using WP_User_Query from which I got the avatar, name and a few ACF that I created for the user registration. Now, I need to obtain a post list of each of the users in my ...
2
votes
1answer
2k views

Increase the page size of the WordPress REST API

A client is using the WordPress REST JSON API with some WordPress data models. We need to hit the WordPress API from the frontend and retreive a few hundred custom posts. Wordpress has a hard limit ...
1
vote
2answers
1k views

WP_Query, tax_query and term_meta: How to?

I have a custom post type product (wine). Each of the following is a custom taxonomy: Vintage (Year of harvesting) [only one per wine] Family (Grape variety) [may be more than one] Size (Bottle Size) ...
1
vote
2answers
51 views

I don't arrive to do order_by title when i have a conditionnal year in a request

I have a problem with this request with get_posts,when I want to order by title with year, order by doesn't work but when I do it without year, the request works. $args = array( '...
1
vote
1answer
448 views

Encrypt / Decrypt Post Title and Details

How can I tap into Wordpress to Encrypt a post title and its details before it gets saved into the database? Then how do I tap into Wordpress to Decrypt the post title and details before it gets ...
0
votes
1answer
41 views

404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice

I have created a 404 error template. whose main portion looks like this → <div class="main col <?php post_class(); ?>"> <h2>Sorry Boss! This Page doesn't exist.</h2&...
1
vote
1answer
22 views

How inefficient is it to use a Custom Post for 4-5 sentences & pull all to 1 page?

Right now, I created a custom post type "resource" that is currently set to hidden. I'm planning on getting all resource posts and displaying them on 1 page. Not like an archive page, but like a post. ...
0
votes
1answer
196 views

How to Get Position of a Post from a category and tag

I am trying to get post positions from categories and tags. All categories and tags are ordered with meta value on my website and the meta key is: option_overall_score Well my plan is displaying ...
0
votes
0answers
92 views

Error get_posts with Custom Taxonomy and OR relation

I've been stuck on this for hours... I did a var_dump($list_items) right before if ( $list_items ) { and it turns up empty, but a var_dump($hold_tax_query) looks (to me) like it should. if($...
0
votes
1answer
566 views

Create a sitemap without a plugin - get parent pages only?

I want to create a sitemap that only includes parent pages only. This is the code I use usually to get parent pages only: $args = array( 'post_type' => 'page', 'post_parent' => 0, '...
0
votes
1answer
1k views

Filtering custom post type query

Thanks to @the_dramatist for the following code in answer to this previous question. I have a follow on, which is that I'd like to use the the following but break it down/filter it so I can pull in ...
0
votes
1answer
799 views

get posts meta query returning the latest post if no meta key found

I have this pretty standard script that looks for a preview or a report (custom post types) which have data stored against them (serialized array) taking the form of a guid. The guid is present on ...
2
votes
1answer
4k views

WP_query category__in not working, only pulls from first category

I wrote a WP_query and the behaviour is weird. I tried almost everything but that's not working. I found a solution but i try to understand. The following queries always returns posts from the first ...
1
vote
1answer
109 views

Multisite - sort merged get_posts() queries

I have a multisite (test) installation of WordPress and want to get the posts of every blog. After hours, I got the solution for that. But now, I have the merged query and like to sort the posts ...
0
votes
1answer
390 views

How to add navigation arrows to manually slide through posts?

I have made this: <?php $args = array( 'numberposts' => '5' ); $recent_posts = wp_get_recent_posts($args); foreach( $recent_posts as $recent ){ if($recent['post_status'...
1
vote
0answers
199 views

get_posts() and WP_query limits 'AND' conditions to a maximum of 6 for meta value queries in Wordpress

The get_posts() function and WP_query in WordPress is limiting me to a maximum of 6 AND conditions for meta value queries. Can I force get_posts() to work with more than 6 AND conditions? Below is ...
0
votes
1answer
568 views

Can not switch the queried post in pre_get_posts hook

I need to dynamically change which page is being loaded based on the URL. It's a translation system, and a page's slug is different for each language. URLs look like that: /en/best-restaurants-in-...
0
votes
1answer
44 views

Posts loop displaying the same post data

My first real day with Wordpress, it's not going well... I just have a simple loop where I wish to display some posts from a specific category. This is my code: <?php $args = array( '...

1 2 3 4 5 15