I’m using this code to have a duplicate post function in WordPress Admin. However, when I add the filter for a custom post type, like this:
add_filter( 'directory_row_actions', 'rd_duplicate_post_link', 10, 2 );
(The Custom Post Type has a registered name of directory
) – it doesn’t add it to the action row underneath the entry title. When I do it for the posts or pages, like this:
add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
it works perfectly. I’ve been reading that post_row_actions
has been deprecated but I can’t find anywhere that says it’s replacement. Does anyone know how to get this working for my Custom Post Type?
2 Answers
As @bonger commented, there is no custom post type filter despite what you’ve read.
To use this filter for a specific post type, the best way is to use the post_row_actions
filter and then test against the passed in $post->post_type
.
I’ve used the code below to add links to the actions row for a specific post type (in this case, myposttype).
This will need to be edited to work for your own post type, and obviously for the new link to actually do anything more code is needed, but this is the idea:
function my_duplicate_post_link($actions, $post)
{
if ($post->post_type=='myposttype')
{
$actions['duplicate'] = '<a href="#" title="" rel="permalink">Duplicate</a>';
}
return $actions;
}
add_filter('post_row_actions', 'my_duplicate_post_link', 10, 2);