0

I'm trying to find a way to display the current user's custom post (each user has only 1 post) content/meta in the sidebar, so the current user can see their custom post's meta. This is what I have so far but I think need to add wp_get_current_user()->ID somewhere...

What I have currently...

<?php
    $authorid = get_the_author_meta( ID, $userID );
            $args4=array('author'=>$authorid,'post_type'=>'CUSTOM-POST-TYPE', 'numberposts'=> -1);
            $cquery4=new WP_Query($args4);
            if($cquery4->have_posts()):
                while($cquery4->have_posts()):
                    $cquery4->the_post();
            ?>

            <?php the_date('j\<\s\u\p\>S\<\/\s\u\p\> M Y'); ?>

            <?
                endwhile;
                wp_reset_postdata();
            endif;
?>

Thinking what I should have?....

<?php
    $authorid = get_the_author_meta( ID, wp_get_current_user()->ID );
            $args4=array('author'=>$authorid,'post_type'=>'CUSTOM-POST-TYPE', 'numberposts'=> -1);
            $cquery4=new WP_Query($args4);
            if($cquery4->have_posts()):
                while($cquery4->have_posts()):
                    $cquery4->the_post();
            ?>

            <?php the_date('j\<\s\u\p\>S\<\/\s\u\p\> M Y'); ?>

            <?
                endwhile;
                wp_reset_postdata();
            endif;
?>
  • Why you do this authorid = get_the_author_meta( ID, wp_get_current_user()->ID );? If you have the ID; the request for get the ID ist not necessary. The user is logged in and you have the ID with wp_get_current_user()->ID. – bueltge Dec 19 '16 at 8:39
  • I don't really know what i'm doing to be honest. This was the best I could find to start me off but i'm still not getting far. – Pete Dec 20 '16 at 3:54
1

The follow source is more formatted, but in the goal the same like your tests. You should see, the first line to get the ID is not necessary. You have the ID of the user, there is present.

If the loop get posts, it print a title and the date. Important is, that the post type exist and have posts.

<?php
    $args = array(
        'author'      => wp_get_current_user()->ID,
        'post_type'   => 'CUSTOM_POST_TYPE',
        'numberposts' => -1,
    );
    $cquery4 = new WP_Query( $args );
    if ( $cquery4->have_posts() ) :
        while( $cquery4->have_posts() ) :
            $cquery4->the_post();

        the_title();
        the_date();

        endwhile;
        wp_reset_postdata();
    endif;
  • Ahhh, thanks. I can see what you were meaning now. – Pete Dec 20 '16 at 13:14

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.