Hi,
by the Author profile i understand you mean an URL to the page created by WPAdverts Authors extension?
If so then right now we do not have a function to generate a link to this page, but you can get it with the code below
$args = array(
'author' => wp_get_current_user()->ID,
'post_type' => 'advert-author',
'posts_per_page' => 1,
'post_status' => array( 'publish', 'advert-hidden' ),
);
$authors = get_posts( $args );
if( isset( $authors[0] ) ) {
$url = get_the_permalink( $authors[0]->ID );
} else {
$url = null;
}
If you would like to merge it with the code above then you can replace wp_get_current_user()->ID with $user->ID.
Hi Greg,
Thanks for the code snippet. It looks like people submitting ads are not added as Authors on that page:
/wp-admin/edit.php?post_type=advert-author
Is there a way to ensure they are added as Authors when the “create account” checkbox is checked and when they post their ad?
Thank you,
Matt
When using the snippet, it gives the same profile URL to anyone who comments. There seems to be only one author and all users commenting inherit his profile URL. Is there something I need to change?
Thank you,
Matt
Hi,
when checking the “create account” checkbox the user will only be registered as a user in wp-admin / Users panel.
If you would like him to have an entry in wp-admin / Authors as well then you can use a wpadverts_user_saved filter to do that
add_filter( "wpadverts_user_saved", function( $user_id ) {
wp_insert_post( array(
'post_title' => $user_id,
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'advert-author',
'post_author' => $user_id
) );
return $user_id;
}, 1000 );
but i would not recommend doing so because you will get a bunch of empty author profiles since there is no where to pull the author data from (except for the Ad itself), it would be much better to ask the user to login and manually fill his profile.