custom post type by author - wp job manager
-
17-01-2021 - |
Question
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?
Solution
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' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange