Page, Post, and CPT ID in Admin columns

Marko Krstić
28 May 2021

From time to time you need to set up a bunch of conditions with Oxygen Builder that requires Page or Posts ID numbers. To get them you need to open every page or post and find it under URL. Much easier is to get numbers directly inside Admin Columns so you don’t need to open them at all.

<?php

add_filter('manage_posts_columns', 'dplugins_posts_columns_id', 5);
add_action('manage_posts_custom_column', 'dplugins_posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'dplugins_posts_columns_id', 5); // for pages
add_action('manage_pages_custom_column', 'dplugins_posts_custom_id_columns', 5, 2); // for pages
 
function dplugins_posts_columns_id($defaults){
    $defaults['wps_post_id'] = __('ID');
    return $defaults;
}
function dplugins_posts_custom_id_columns($column_name, $id){
    if($column_name === 'wps_post_id'){
            echo $id;
    }
}

?>

Scripts Organizer Settings

Trigger Location: Everywhere
Script Location: PHP

screenshot 2021 04 15 at 21.29.12 1

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy