I have a custom post type products. I've made a custom admin column in php using the
manage_${post_type}_posts_columns action
For the value, I have the $post_id and I want to use that to check if that post is using a layout for it's content field. If it is using the layout plugin to design the content, I want to show a link to jump to that editor so the admin doesn't have to click the post and then click "Edit with Layouts"
Hello,
The Layouts plugin is using a hidden custom field "_layouts_template" to store the layout slug in each post, so you can get the layout slug value with WordPress function get_post_meta(), for example:
$layout_slug = get_post_meta(get_the_ID(), '_layouts_template', true);
https://developer.wordpress.org/reference/functions/get_post_meta/
Then use slug to get layout post ID with function get_posts()
https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
name (string) - use post slug.
That works to get the overall layout for the post; however, I'm looking to see if the post is using the content layout editor and not if the post type uses a layout template.
Is that a different custom field?
Yes, you are right, it is another custom hidden post field "_private_layouts_template_in_use", field value is "yes".
Ok, so if "_private_layouts_template_in_use" returns "yes", then where do I get that layout ID (or slug) for the content layout editor?
I'm doing something like this in the admin column:
$layout_slug = get_post_meta($post_id, '_private_layouts_template_in_use', true);
$query = new WP_Query(array('name' => $layout_slug));
$layout_posts = $query->posts;
if(count($layout_posts)){
echo "<a href='/wp-admin/admin.php?page=dd_layouts_edit&layout_id=${layout_posts[0]->ID}&action=edit'>Edit Layout</a>";
}
Obviously this won't do anything because "_private_layouts_template_in_use" is going to give me a "yes" and not a slug or ID of the layout. Can I use this key to check if the layout is attached and another key to get the actual ID?
The URL parameter "layout_id" value is using same value as post ID, for example:
[php]
if( get_post_meta($post_id, '_private_layouts_template_in_use', true) == 'yes' ){
echo "Edit Layout";
}
[php]
For your reference.