Let's say I have a query stored in a array.
I want to parse this array, find the first posts inside this array that match a certain value from a certain key, and so extract the whole post.
Is there a elegant way to do it ? Or, is it possible to run a query_posts() inside this array ?
Thanks !
Edit:
Sorry, just learning to use this fantastic website, need to learn correct use.
The purpose is to make a get_posts()
, and display the posts not in a row, but at different places in the homepage where there is a place for a Beauty category post, a Mode category Post, etc. As any post could be in several categories, I cannot just ask for the last post in the category: a post could be in two places at the same time.
My idea is to just make a get_posts query, store the result, and parse it so i could take record of what post are displayed and what are not.
So, I make a query with get_posts()
are store result in a variable. As I don't want certain posts to stay in the query, I use 'post__not_in'
, which is array
with posts ID
I don't want.
function request_highlights($exclude_ids) {
/* request that will populate my hightlight feed */
$args = array(
'numberposts' => 16,
'category' => null,
'orderby' => 'post_date',
'order' => 'DESC',
'post__not_in' => $exclude_ids,
);
return get_posts( $args );
}
$highlights_posts = request_highlights($slides_id);
So at this point, I have a variable which is a objet, I guess, with all needed data.
What I want to do is to get, say, the first post in the objet that has the cat_ID=5
(for example).
What i'm doing right now is :
foreach ($highlights_posts as $highlights_post) {
$fetched_post = get_the_category($highlights_post->ID);
foreach ( $fetched_post as $fetch_cat) {
if ($fetch_cat->cat_ID == $cat_sq) {
$sq_post_id = $fetch_cat->cat_ID;
break 2;
}
}
}
// stuff to do like get_post($sq_post_id);
Now i realise that I would need to remove that post ID
from my list $highlights_posts
so I cannot pull it twice. I guess i need to learn more about arrays ?
/* requete pour peupler highlights */ $highlights_posts = request_highlights($slides_id); function request_highlights($exclude_ids) { /* la requete qui va peupler le slider */ $args = array( 'numberposts' => 16, 'category' => null, 'orderby' => 'post_date', 'order' => 'DESC', 'post__not_in' => $exclude_ids, ); return get_posts( $args ); }