Answer the question
In order to leave comments, you need to log in
How to display in a WordPress table only certain posts by their ID?
I am writing a plug-in for the VI that performs some kind of manipulation with records. After that, I want to redirect the user to a table with records, but at the same time, by default, only display those that I have changed. I tried adding a parameter to the link post__in
like WP_Query
- /wp-admin/edit.php?post__in=1,2,3,4
- but that didn't work.
Answer the question
In order to leave comments, you need to log in
I haven't tested the code, but I think it's worth digging somewhere in this direction.
function posts_for_specific_ids($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
$ids = explode(',', $_GET['post__in']);
$query->set('post__in', $ids);
return $query;
}
add_filter('pre_get_posts', 'posts_for_specific_ids');
why are you trying to get posts with a get request? do as stated in the documentation
$args = array(
'post__in' => array(43,23,65)
);
$posts = get_posts($args);
foreach ($posts as $p) :
//post!
endforeach;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question