Hi Want to show custom post/posts of logged in user as list with Edit button with shortcode if possible
After trying and searching so much I found one solution but it show link of posts in menu as item But I don't know how can i make it as shortcode to show on post/posts on page with edit link.
Reffernce Code
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' );
Credit: Daniel C
Original Answer at Get post ID of current logged in user and add a link to the menu
I thankful if you spare some time and answer my this small question
Thanks in Advance.
Final Answer
Credit: Elvine https://stackoverflow.com/users/701666/elvin85
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]');