• Resolved hammeri1

    (@hammeri1)


    Hi Greg,

    A while back you helped me default the ad-title depending on the ad category. I’ve been trying to modify this to include the logged-in user ID in the ad-title too by incorporating $current_user = wp_get_current_user(); $current_user->display_name but not having any success. The code snippet you gave me originally was:

    add_filter( “adverts_form_bind”, “my_adverts_form_bind”, 1000 );
    function my_adverts_form_bind( $form ) {
    try {
    if( $form->get_value( “post_title” ) ) {
    return $form;
    }
    $titles = array(
    “buyer” => “Buyer”,
    “seller” => “Seller”,
    );
    $key = adverts_request( “preselected_category” );
    if( $form->get_scheme( “name” ) == “advert” && isset( $titles[$key] ) ) {
    $form->set_value( “post_title”, $titles[$key]);
    }
    } catch(Exception $e) {
    // do nothing
    }
    return $form;
    }

    Can you point me in the right direction?

    Thanks,

    Richard.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    to append the current user id to the post_title you would need to replace the

    
    $form->set_value( “post_title”, $titles[$key]);
    

    with

    
    $display_name = "";
    if( get_current_user_id() > 0 ) {
      $display_name = wp_get_current_user()->display_name;
    }
    $form->set_value( "post_title", $titles[$key] . " " . $display_name );
    
    Thread Starter hammeri1

    (@hammeri1)

    Brilliant, works just as I’d hoped.

    Thanks,

    Richard.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ad Title to include logged in user name’ is closed to new replies.