Access $post object when adding custom columns to list table

Question

We’ve got a custom post type called ‘products’ which stores all of its additional meta data in a separate table for performance reasons (we’re expecting 1000s of records). We have extended the query performed on the ‘Products’ list table page in the admin area to include all the additional meta data in the resulting ‘posts’ object (eg. product_supplier, product_featured etc).

The issue is that we want to add some additional columns to the list table WITHOUT performing additional DB queries to lookup the data (since it’s already in our ‘posts’ object mentioned above). We would usually use the filter ‘manage_product_posts_custom_column’ to define the custom column content but this is only passed the $post_id rather than the $post object (which has all the info we need without additional queries).

The way I see it we either need to make the $post object a global variable so we can access it from within the ‘manage_product_posts_custom_column’ filter or we need to, somehow, add addition column methods (which are passed the $item object as as such would have the data). This second method could use a custom List Table class is suppose but we would only want to extend the WP_Posts_List_Table to add the addition column methods. The issue with that is I don’t know how to do it…

Hopefully this all makse sense and someone out there will have an idea of how to achieve this.

Cheers,

Will

0
, Will Fairhurst 8 months 0 Answers 82 views 0

Leave an answer