0

Hy, I am working with wp job manager, and I would like to list job applications by user, under ultimate member tabs. I have tried using this code, but it shows me all applications

function custom_shortcode() {

    $args = array( 'post_type' => 'job_application',
 'author'=>$author_id,  );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        the_title();
        echo '<div class="entry-content">';
        the_content();
        echo '</div>';
    endwhile;
}
add_shortcode( 'query_my_posts', 'custom_shortcode' );

Also i have tried this method https://suiteplugins.com/how-to-change-the-post-type-on-ultimate-member-posts-tab/

But no luck, any help?

2

1 Answer 1

1

As others have stated, you are going to want to add an argument to your shortcode to set a specific author_id. Once you have that you can then perform your query.

I have not tested, but the following code should put you on the track. The shortcode would be [query_my_posts author_id="#"]

function custom_shortcode() {
    $atts = shortcode_atts(array(
        'author_id' => '',
    ), $atts);

    $args = array( 
        'post_type' => 'job_application',
        'author'=> $atts['author_id'],  
    );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        the_title();
        echo '<div class="entry-content">';
        the_content();
        echo '</div>';
    endwhile;
}
add_shortcode( 'query_my_posts', 'custom_shortcode' );
1
  • Yes , but this needs me to enter user ID every time in the shortcode, any way I used get current user ID to define author, and now it work, Thanks guys
    – dado
    Commented Dec 21, 2016 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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