-2

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]');
Mye Space
  • 93
  • 1
  • 14
  • 1
    `After trying and searching so much` Yet your code contains nothing about a shortcode? – ProEvilz Oct 25 '17 at 11:04
  • 2
    Shortcodes are extremely simple to set up. See the [docs](https://developer.wordpress.org/reference/functions/add_shortcode/) – ProEvilz Oct 25 '17 at 11:06
  • Hi thanks for the comment .... Here i not only searching for shortcode ... but Instead just links of post i want edit link of post / posts of logged-in author – Mye Space Oct 25 '17 at 11:46

1 Answers1

1
    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]');
Elvin Haci
  • 3,503
  • 1
  • 17
  • 22
  • "// " after domain and I got link to read post ... I need Link to edit the post – Mye Space Oct 25 '17 at 12:39
  • Hi Elvin... Problem Solved.... There was extra "Echo" gave me error in your last suggestion but i removed it now working fine.... you really Help me lot... Thank you so much For you kind help and efforts – Mye Space Oct 25 '17 at 12:59
  • yes, that was common example, i though you would get the idea and remove it. :) i am glad the problem is solved now. you can mark the answer as a solution – Elvin Haci Oct 25 '17 at 13:04
  • Sorry I not expert as you :).... Yes I updated the question with correct answer... Again Thanks you – Mye Space Oct 25 '17 at 13:07