![](/img/trans.png)
[英]How Can I Get the Current Logged-In User with WordPress SHORTINIT
[英]WordPress Get Current Logged-in users post or posts with edit link
嗨,如果可能的话,希望将登录用户的自定义帖子/帖子显示为带有带有短代码的“编辑”按钮的列表
在尝试和搜索了这么多之后,我找到了一个解决方案,但它将菜单中的帖子链接显示为项目但我不知道如何将其作为短代码显示在带有编辑链接的页面上的帖子/帖子上。
参考代码
function new_nav_menu_items( $items ) {
global $current_user;
$args = array(
'post_type' => 'job_listing',
'author' => $current_user->ID,
'status' => 'publish',
'posts_per_page' => 1
);
$jobs = get_posts( $args );
$link = '<li><a href="' . get_permalink( $jobs->ID ) . '">Your Job</a></li>';
// add link to the end of the menu
$items = $items . $link;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
信用:丹尼尔C
获取当前登录用户的帖子 ID处的原始答案并添加菜单链接
如果您能抽出一些时间回答我的这个小问题,我将不胜感激
提前致谢。
最终答案
function user_items( ) {
if (!is_user_logged_in()) return;
$items='';
$args = array(
'post_type' => 'ait-item',
'author' => get_current_user_id(),
'status' => 'publish',
'posts_per_page' => 10
);
$jobs = get_posts( $args );
foreach($jobs as $job){
$link = '<a href="'.home_url('wp-admin/post.php?post='.$job->ID.'&action=edit').'">UPDATE YOUR VENU AND OFFERS</a> </BR>';
$items = $items . $link;
}
return $items;
}
add_shortcode( 'your_job', 'user_items' );
//usage in post content [your_job]
//usage inside code do_shortcode('[your_job]');
function user_items( ) {
if (!is_user_logged_in()) return;
$items='';
$args = array(
'post_type' => 'job_listing',
'author' => wp_get_current_user(),
'status' => 'publish',
'posts_per_page' => 1
);
$jobs = get_posts( $args );
foreach($jobs as $job){
$link = '<li><a href="' . get_permalink( $jobs->ID ) . '">'.$jobs->post_title.'</a></li>';
$items = $items . $link;
}
return $items;
}
add_shortcode( 'your_job', 'user_items' );
//usage in post content [your_job]
//usage inside code do_shortcode('[your_job]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.