admin管理员组文章数量:1130349
I am using custom post_type and inside the loop I echo get_delete_post_link but there is nothing echoing.
<?php
$wpquery = new WP_Query('post_type=myposts');
if( $wpquery->have_posts() ) {
while ($wpquery->have_posts()) : $wpquery->the_post();
$id = get_the_ID();
//just a test to see can I get post IDs and I get them
echo $id; ?>
<a href="<?php echo get_delete_post_link($id); ?>">Delete</a>
<?php endwhile; }
wp_reset_query();?>
This is the output
<a href="">Delete</a>
I am using custom post_type and inside the loop I echo get_delete_post_link but there is nothing echoing.
<?php
$wpquery = new WP_Query('post_type=myposts');
if( $wpquery->have_posts() ) {
while ($wpquery->have_posts()) : $wpquery->the_post();
$id = get_the_ID();
//just a test to see can I get post IDs and I get them
echo $id; ?>
<a href="<?php echo get_delete_post_link($id); ?>">Delete</a>
<?php endwhile; }
wp_reset_query();?>
This is the output
<a href="">Delete</a>
Share
Improve this question
edited May 14, 2013 at 2:46
deimos
asked May 14, 2013 at 2:22
deimosdeimos
609 bronze badges
2 Answers
Reset to default 3Is the user logged in and is allowed to delete posts of this post type? There are three checks inside the get_delete_post_link function before anything starts happening:
if ( !$post = get_post( $id ) )
return;
$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object )
return;
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
return;
I'm wild-guessing it's the third check that's failing in your case. You can paste them into your code and replace return; with debugging code to see what's going on:
if ( !$post = get_post( $id ) ) {
echo 'could not get post. ';
} else {
echo 'got post. ';
}
$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object ){
echo 'could not get post object. ';
} else {
echo 'got post object. ';
}
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ){
echo 'user does not have proper capability. ';
} else {
echo 'user is ok to delete this post. ';
}
All I can see that might cause this is the check for delete permissions.
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
return;
If your user doesn't have delete permissions for the post the function returns nothing.
There could also be a filter on get_delete_post_link.
I am using custom post_type and inside the loop I echo get_delete_post_link but there is nothing echoing.
<?php
$wpquery = new WP_Query('post_type=myposts');
if( $wpquery->have_posts() ) {
while ($wpquery->have_posts()) : $wpquery->the_post();
$id = get_the_ID();
//just a test to see can I get post IDs and I get them
echo $id; ?>
<a href="<?php echo get_delete_post_link($id); ?>">Delete</a>
<?php endwhile; }
wp_reset_query();?>
This is the output
<a href="">Delete</a>
I am using custom post_type and inside the loop I echo get_delete_post_link but there is nothing echoing.
<?php
$wpquery = new WP_Query('post_type=myposts');
if( $wpquery->have_posts() ) {
while ($wpquery->have_posts()) : $wpquery->the_post();
$id = get_the_ID();
//just a test to see can I get post IDs and I get them
echo $id; ?>
<a href="<?php echo get_delete_post_link($id); ?>">Delete</a>
<?php endwhile; }
wp_reset_query();?>
This is the output
<a href="">Delete</a>
Share
Improve this question
edited May 14, 2013 at 2:46
deimos
asked May 14, 2013 at 2:22
deimosdeimos
609 bronze badges
2 Answers
Reset to default 3Is the user logged in and is allowed to delete posts of this post type? There are three checks inside the get_delete_post_link function before anything starts happening:
if ( !$post = get_post( $id ) )
return;
$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object )
return;
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
return;
I'm wild-guessing it's the third check that's failing in your case. You can paste them into your code and replace return; with debugging code to see what's going on:
if ( !$post = get_post( $id ) ) {
echo 'could not get post. ';
} else {
echo 'got post. ';
}
$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object ){
echo 'could not get post object. ';
} else {
echo 'got post object. ';
}
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ){
echo 'user does not have proper capability. ';
} else {
echo 'user is ok to delete this post. ';
}
All I can see that might cause this is the check for delete permissions.
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
return;
If your user doesn't have delete permissions for the post the function returns nothing.
There could also be a filter on get_delete_post_link.
本文标签: plugin developmentCan39t echo getdeletepostlink
版权声明:本文标题:plugin development - Can't echo get_delete_post_link 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749246294a2338935.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论