• Resolved vj2k

    (@vj2k)


    Hi,

    Am looking at extending an existing Custom field (of another plugin) as a select tag for the charitable plugins.

    I have close to 100 students who may be sponsored, Our idea is to allow the user to select the student prior to donating and this may be saved in the donations CPT.

    I tried the following code

    function ed_collect_student_name( $fields, Charitable_Donation_Form $form ) {

    query_posts( array( ‘post_type’ => ‘student’,’posts_per_page’=>-1,$echo=”false” ));

    while ( have_posts() ) : the_post();

    $title_list[] = array(‘name’ => the_title(), ‘value’ => the_title());

    endwhile;

    $fields[‘student_name’] = array(
    ‘label’ => __( ‘student Name’, ‘your-namespace’ ),
    ‘type’ => ‘select’,
    ‘priority’ => 24,
    ‘value’ => $form->get_user_value( ‘donor_student_name’ ),
    ‘options’ => $title_list,
    ‘required’ => true,
    ‘data_type’ => ‘user’
    );
    return $fields;
    }
    add_filter( ‘charitable_donation_form_user_fields’, ‘ed_collect_student_name’, 10, 2 );

    function ed_donation_export_add_student_name_column( $columns ) {
    $columns[‘student_name’] = __( ‘student Name’, ‘your-namespace’ );
    return $columns;
    }
    add_filter( ‘charitable_export_donations_columns’, ‘ed_donation_export_add_student_name_column’ );

    function ed_donation_export_add_student_name_value( $value, $key, $data ) {
    if ( ‘student_name’ != $key ) {
    return $value;
    }
    return ed_donation_get_student_name( charitable_get_donation( $data[‘donation_id’] ) );
    }
    add_filter( ‘charitable_export_data_key_value’, ‘ed_donation_export_student_name_value’, 10, 3 );

    What I get is the entire post being displayed in a loop instead only the Post Title and the drop down box only has numbers.

    Could you assist

    Vijay

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Vijay,

    This bit looks wrong to me:

    $title_list[] = array(‘name’ => the_title(), ‘value’ => the_title());
    

    Try this instead:

    $title_list[ get_the_ID() ] = get_the_title();
    

    Cheers,
    Eric

    Thread Starter vj2k

    (@vj2k)

    Hi Eric,

    I tried this code

    function get_myposttype_options($argument) {

    $get_post_args = array(
    ‘post_type’ => $argument,
    ‘posts_per_page’ => -1
    );

    $options = array();
    foreach ( get_posts( $get_post_args ) as $post ) {
    $title = get_the_title( $post->ID );

    $options[] = array(
    $title => $title,

    );
    }

    return $options;
    }

    function ed_collect_swimmer_name( $fields, Charitable_Donation_Form $form ) {
    $fields[‘swimmer_name’] = array(
    ‘label’ => __( ‘swimmer Name’, ‘your-namespace’ ),
    ‘type’ => ‘select’,
    ‘priority’ => 24,
    ‘value’ => $form->get_user_value( ‘donor_swimmer_name’ ),
    ‘options’ => get_myposttype_options(‘swimmer’),
    ‘required’ => true,
    ‘data_type’ => ‘user’
    );
    return $fields;
    }

    add_filter( ‘charitable_donation_form_user_fields’, ‘ed_collect_swimmer_name’, 10, 2 );
    /**

    The drop down works but there is a number before each name ??

    Rest is perfect.
    Vijay

    Try this instead:

    $options = array();
    foreach ( get_posts( $get_post_args ) as $post ) {
        $options[ $post->ID ] = get_the_title( $post->ID );
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Extend existing Custom Post Type’ is closed to new replies.