Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Joey

Post__in array of IDs on edit screen?

Hi

Is it possible to have something like /wp-admin/edit?my_post_ids=100,200,300,400 where the edit screen just shows those 4 posts

I’ve tried a solution on stack exchange for the regular wordpress screen, but haven’t been able to get it to work with Admin Columns Pro?

/**
 * Usage:
 * http://example.com/wp-admin/edit.php?my_post_ids=4088,4090,4092,4094
 */
add_filter( 'pre_get_posts', 'limit_post_list_wpse_96418' );

function limit_post_list_wpse_96418( $query ) 
{
    // Don't run on frontend
    if( !is_admin() )
        return $query;

    global $pagenow;

    // Restrict to Edit page
    if( 'edit.php' !== $pagenow )
        return $query;

    // Check for our filter
    if( !isset( $_GET['my_post_ids'] ) )
        return $query;

    // Finally, filter
    $limit_posts = explode( ',', $_GET['my_post_ids'] ); // Convert comma delimited to array    
    $query->set( 'post__in', $limit_posts );      

    return $query;
}

Essentially I’d like to be able to access one url with a list of post IDs, and just show those posts on the edit screen? Thanks in advance.

4 years, 5 months ago
Joey

Sorry I can’t edit the post above – it should read /wp-admin/edit.php?my_post_ids=100,200,300,400

4 years, 5 months ago
Joey

Right, think I’ve sorted it – for some reason it didn’t like “my_post_ids” as a name, so I’ve changed it back to the following and it works fine.

 /**
 * Usage:
 * http://example.com/wp-admin/edit.php?my_pids=4088,4090,4092,4094
 */
add_filter( 'pre_get_posts', 'limit_post_list_wpse_96418' );

function limit_post_list_wpse_96418( $query ) 
{
    // Don't run on frontend
    if( !is_admin() )
        return $query;

    global $pagenow;

    // Restrict to Edit page
    if( 'edit.php' !== $pagenow )
        return $query;

    // Check for our filter
    if( !isset( $_GET['my_pids'] ) )
        return $query;

    // Finally, filter
    $limit_posts = explode( ',', $_GET['my_pids'] ); // Convert comma delimited to array    
    $query->set( 'post__in', $limit_posts );      

    return $query;
}
 
 
 /**
End
 */
4 years, 5 months ago
Stefan van den Dungen Gronovius
Developer

Thanks for your input.
I don’t see a way to do this currently with our plugin.
We could have a look if we can enhance our Smart Filtering feature to support a range of ids instead of just selecting a single value that must be included or excluded. For now, the hook you used seems the easiest way to do what you want. The next step is to create an interface for it so you don’t have to type in the id’s yourself in the URL.

4 years, 5 months ago
Joey

For me the interface isn’t really an issue as I’ve custom coded a page which automatically generates the link with the relevant IDs I need – however other people may find it useful if they can generate an admin columns layout based on a select group of IDs? Thanks, Joey

4 years, 5 months ago

You must be logged in to reply to this topic.