Title: User&#8217;s Adverts question
Last modified: January 15, 2020

---

# User’s Adverts question

 *  Resolved [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/)
 * Hi!
    I have question about user’s ads. I’m using Ultimate Member plugin on my
   site, and there is a social activity page, something like on Facebook.when user
   posting ad i need to display user’s ad on this activity page. Will be thankful
   for any advice.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12331382)
 * Hi,
    currently, we do not have an integration with Ultimate Member, so inserting
   a new Ad in the user activity stream will require some custom programming.
 * You can use the publish_advert post status transition to add a new activity when
   the user Ad is published.
 * For example the code below will fire when new Ad is published
 *     ```
       add_action( "publish_advert", "on_advert_publish" );
       function on_advert_publish( $post_id ) {
           $advert = get_post( $post_id );
           // add UM activity here
       }
       ```
   
 * That being said i am not really familiar with UM API so i am not sure how to 
   add the activity, you would need to ask their support what function to use to
   do that.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12331955)
 * Thanks for advice, Greg!
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12341518)
 * Hi, Greg!
    I have got code snippet from UM support and i combined with your, 
   so i have this code now:
 * //Adverts on social activity wall
 * add_action( “publish_advert”, “on_advert_publish” );
    function on_advert_publish(
   $post_id ) { $advert = get_post( $post_id ); // add UM activity here function
   um_activity_new_cpt( $post_id ) { if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE)
   return; if ( get_post_type( $post_id ) != ‘cpt_slug’ || get_post_status( $post_id)!
   = ‘publish’ ) return;
 *  if ( ! UM()->options()->get(‘activity-new-post’) )
    return;
 *  $post = get_post( $post_id );
    $user_id = $post->post_author;
 *  um_fetch_user( $user_id );
    $author_name = um_user(‘display_name’); $author_profile
   = um_user_profile_url();
 *  if (has_post_thumbnail( $post_id ) ) {
    $image = wp_get_attachment_image_src(
   get_post_thumbnail_id( $post->ID ), ‘large’ ); $post_image = ‘<span></span>’;}
   else { $post_image = ”; }
 *  if ( $post->post_content ) {
    $post_excerpt = ‘<span>’ . wp_trim_words( strip_shortcodes(
   $post->post_content ), $num_words = 25, $more = null ) . ‘</span>’; } else { 
   $post_excerpt = ”; }
 *  UM()->Activity_API()->api()->save(
    array( ‘template’ => ‘new-post’, ‘wall_id’
   => $user_id, ‘related_id’ => $post_id, ‘author’ => $user_id, ‘author_name’ =>
   $author_name, ‘author_profile’ => $author_profile, ‘post_title’ => ‘<span>’ .
   $post->post_title . ‘</span>’, ‘post_url’ => get_permalink( $post_id ), ‘post_excerpt’
   => $post_excerpt, ‘post_image’ => $post_image, ) ); } } add_action(‘save_post’,‘
   um_activity_new_cpt’, 99999, 1 );
 * It’s actually work, but unfortunately there is some errors.
    Can you please check
   this code, is there any bugs? Thank you!
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12341675)
 * Alsi they said, that i need to change the cpt_slug with WP Adverts post type.
   Maybe it is the problem?
    Thanks!
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12343146)
 * It seems you have it mixed up, try using just the code they have sent, but in
   the code they have sent replace ‘cpt_slug’ with ‘advert’.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12415421)
 * Hi Greg!
    Little question, from Ultimate Member developers i have got this code
   snippet:
 * add_action(“adverts_post_type”, “customize_adverts_post_type”);
 * function customize_adverts_post_type( $args ) {
    $args[“supports”][] = “thumbnail”;
   return $args; }
 * They said, that WPAdverts doesn’t have a featured box area,so thats why i can’t
   see featured image of the post on social activity.Also they said, if i add this
   snippet it must work, but unfortunately not working, is this code written correctly?
   
   Thank You!
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12416598)
 * Hi,
    the code seems fine when you go to wp-admin / Classifieds panel and edit
   one of the Ads check if in the right sidebar you have a Thumbnail/Featured widget(
   which allows selecting the featured image) if you do then the code works properly.
 * BTW. Most likely what they meant is that you need to have featured images enabled
   and select a featured image for the Ad.
 *  Thread Starter [zonepluss](https://wordpress.org/support/users/zonepluss/)
 * (@zonepluss)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12416689)
 * Thanks for help Greg!!!
    Now it works fine, i can see the image, i set POST IMAGE,
   but when users post ads how can they set POST IMAGE?
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12420637)
 * They can select a main image in the gallery, or you can install the Force Featured
   Image snippet [https://github.com/simpliko/wpadverts-snippets/blob/master/force-featured-image/force-featured-image.php](https://github.com/simpliko/wpadverts-snippets/blob/master/force-featured-image/force-featured-image.php)
   which will select a featured image automatically if none is selected by the user.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘User’s Adverts question’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/users-adverts-question/#post-12420637)
 * Status: resolved