BuddyDev

Search

Custom fields on user post

  • Participant
    Level: Initiated
    Posts: 4
    Irene on #708

    Hello there 🙂

    I have a custom post type with custom fields it works good from the dashboard.

    But I want the user to make a custom-post from their buddypress profile.
    With the plugins buddyblog and bp front end, it works, but the custom fields are not showing..

    In the bp-simple-front-end/form.php I see this code (Line 58):
    —-

    <?php //custom fields ?>
    <?php if($this->has_custom_fields()):?>
    <?php echo “<div class=’simple-post-custom-fields’>”;?>
    <?php if( $this->has_visible_meta() ):?>
    <h3><?php echo $this->custom_field_title;?></h3>
    <?php endif;?>
    <?php $this->render_custom_fields();?>
    <?php echo “</div>”;?>
    <?php endif;?>

    —-
    Should I do something with that?

  • Keymaster
    (BuddyDev Team)
    Posts: 19855
    Brajesh Singh on #709

    Hi Irene,
    Welcome to BuddyDev forums.

    No, you don’t need to modify that. Instead you can filter the buddyblog form settings and ask it to disply the form for adding meta.

    You can filter it like this

    
    add_filter( 'buddyblog_post_form_settings', 'buddydev_custom_buddyblog_settings' );
    
    function buddydev_custom_buddyblog_settings( $settings ) {
    	
    	$custom_fields = $settings['custom_fields'];
    	
    	$custom_fields['new_meta_key'] = 	 array(
    					'type'    => 'text',
    					'label'   => '',
    					'default' => ''
    				);
    	
    	//and repeat
    	
    	//then update settings
    	
    	$settings['custom_fields'] = $custom_fields;
    	
    	return $settings;
    }
    
    

    Here is a post that details what meta fields are available

    https://buddydev.com/support/forums/topic/custom-field-in-bp-simple-front-end-post/#post-383

    Hope that helps.

  • Participant
    Level: Initiated
    Posts: 4
    Irene on #710

    Thanks Brajesh.
    And thank you for a swift reply 🙂

    It made me a bit more confused..
    That filter you have added here, where should I upload that?

    My post type has created with this plugin –
    https://wordpress.org/plugins/types/
    It saves the fields in fields group, does that make any difference?

    I have created a test field with a textfield called testcf.
    And uploaded to my-functions.php

    So the code should be like this, right;

    add_filter( ‘buddyblog_post_form_settings’, ‘buddydev_custom_buddyblog_settings’ );

    function buddydev_custom_buddyblog_settings( $settings ) {

    $custom_fields = $settings[‘testcf’];

    $custom_fields[‘new_meta_key’] = array(
    ‘type’ => ‘text’,
    ‘label’ => ‘test custom field text’,
    ‘default’ => ”
    );

    //and repeat

    //then update settings

    $settings[‘testcf’] = $custom_fields;

    return $settings;
    }

    But I don’t get any result..

  • Keymaster
    (BuddyDev Team)
    Posts: 19855
    Brajesh Singh on #711

    You can put the code in your theme’s functions.php or bp-custom.php inside the plugin directory.

    The code should be

    
    
    add_filter( 'buddyblog_post_form_settings', 'buddydev_custom_buddyblog_settings' );
    
    function buddydev_custom_buddyblog_settings( $settings ) {
    
    	$custom_fields = $settings['custom_fields'];
    
    	$custom_fields['testcf'] = array(
    		'type'		=> 'text',
    		'label'		=> 'test custom field text',
    		'default'	=> ""
    	);
    
    	//and repeat
    
    	//then update settings
    
    	$settings['custom_fields'] = $custom_fields;
    
    	return $settings;
    }
    
    

    Hope that helps.

    PS. you can use backticks(`) to post code block here.

  • Participant
    Level: Initiated
    Posts: 4
    Irene on #712

    Okay, I think I get it now. Thank you so much.

    I created a select with two options, and it pops up for the user. Yaaah!

    However I get this error:
    Warning: Invalid argument supplied for foreach() in wp-content/plugins/bp-simple-front-end-post/core/classes/class-edit-form.php on line 523

    This one was only for testing, so maybe I just need to type in some info
    Maybe you would like to know 🙂

    Again thank you!!

  • Participant
    Level: Initiated
    Posts: 4
    Irene on #713

    Maybe I was a bit to fast there…

    I get it to the user blog/post page, but only date and text shows like textfields.

    But none af the data I type in there, will get to the single-cpt.php?

  • Keymaster
    (BuddyDev Team)
    Posts: 19855
    Brajesh Singh on #714

    Hi Irene,
    Are you referring to the edit form display or display on single post page? Also, are you letting the single post to be displayed on profile on their own individual normal pages.

  • Participant
    Level: Initiated
    Posts: 4
    Irene on #715

    That must be display on single post page.

    Right now I’m getting the values typed in, in the form (dashboard/custom post type and field)
    – These values should be types in from their buddypress profile.

    I’m using this code on single-cpt.php – Which is showing the final post:

    <h4> Price: <?php echo types_render_field('show-price'); ?> EURO </h4>

    where ‘show-price’ is the slug from types’ custom field group.

    On their individual pages, under blog (buddyblog) is there a list of the posts that user has created.
    When clicked it goes to the single-cpt page.

    Hope that makes sense.

  • Keymaster
    (BuddyDev Team)
    Posts: 19855
    Brajesh Singh on #718

    Hi Irne,
    i haven’t used types plugin, so Can’t say much about that. Can you please try this code instead.

    
    
    <h4> Price: <?php echo get_post_meta( get_the_ID(), 'show-price', true ); ?> EURO </h4>
    
    

    Does that work?

You must be logged in to reply to this topic.

This topic is: not resolved