1

I'm attempting to turn users' posts into menu items, without luck.

Here's what I have so far, but not working. I would like to use the Advanced custom content by adding a shortcode.

add_shortcode( 'current-posts' , 'ss_get_current_posts' );
function ss_get_current_posts(){
global $current_user;
get_currentuserinfo();
$author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
$author_posts = new WP_Query($author_query);
while ($author_posts->have_posts()) : $author_posts->the_post();
    $list = '<ul class="ubermenu-submenu ubermenu-submenu-id-122-col-0 ubermenu-submenu-type-stack">';
    $list .= '<a class="ubermenu-target ubermenu-target-with-icon ubermenu-item-layout-icon_left" href="';
    $list .= the_permalink();
    $list .= '" title="';
    $list .= the_title_attribute();
    $list .= '"><span class="ubermenu-target-title ubermenu-target-text">';
    $list .= the_title();
    $list .= '</span></a></ul>';                 
endwhile;
return $list;
}

I can actually see the list, but not as links inside the submenu. What is the correct way to do this?

2

the_permalink(), the_title() by default echo their value. As you want to store that value in a variable you will need to return the values instead. get_the_permalink(), get_the_title() are two similar functions that return the value instead of echo.

So you new code may look something like this:

$list = '<li class="ubermenu-submenu ubermenu-submenu-id-122-col-0 ubermenu-submenu-type-stack">';
$list .= '<a class="ubermenu-target ubermenu-target-with-icon ubermenu-item-layout-icon_left" href="';
$list .= get_the_permalink();
$list .= '" title="';
$list .= get_the_title();
$list .= '"><span class="ubermenu-target-title ubermenu-target-text">';
$list .= get_the_title();
$list .= '</span></a></li>';
  • Thank you! Is there any obvious reason why I'm only getting one answer from the query? – Fid Jun 2 '16 at 12:53
  • Nevermind, the <ul> was incorrect. – Fid Jun 2 '16 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.