• Resolved sublimebydesign

    (@sublimebydesign)


    Hi,

    I appreciate that you have a Custom Fields add-on, however it’s currently in Beta, and I already have 70+ fields in Elliot Condons’ Advanced Custom Fields (ACF) plugin, some of which are field types that aren’t provided by CF yet (even if I could export from ACF and import to CF). I have used ACF with other sites and various other plugins installed without issue, but find the usual <?php the_field(‘my_field’); ?> doesn’t work in the appropriate page (add.php) with override-templates.php installed. The child theme template overrides are working generally. How can I get it to work?

    I would prefer to use your plugin rather than one of the poorly coded Classified listings Themes available. I’m happy to use your other add-ons 🙂

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

    (@gwin)

    Hi, i am not that familiar with the ACF API, but it seems you might need to use this function as

    
    <?php the_field('my_field', $post_id) ?>
    

    that is explicitly passing the post id should fix it.

    https://www.advancedcustomfields.com/resources/the_field/

    Thread Starter sublimebydesign

    (@sublimebydesign)

    It doesn’t work, but

    <?php acf_form(array(
    'post_id' => $_REQUEST['id'],
    'form' => false,
    'field_groups' => array(2090),
    )) ?>

    an array does. I’m not clear why.

    Plugin Author Greg Winiarski

    (@gwin)

    Ok, but note that depending on the file in which you are adding this code $post_id might be null, in this case you might need to use

    
    <?php the_field('my_field', $_REQUEST['id']) ?>
    
    Thread Starter sublimebydesign

    (@sublimebydesign)

    Hi Greg,

    The above isn’t working on the required pages. ACF includes a tool for exporting field groups to PHP that generates code to paste into functions.php to register a local version of the selected field group(s): “A local field group can provide many benefits such as faster load times, version control & dynamic fields/settings”.

    I’ve exported one ACF field group as an example; perhaps you could let me know whether it’s likely that it could be adapted to integrate with WPAdverts and how to go about this? By integrate I mean these fields could appear on the add page, be submitted, save, appear on the edit page etc. ACF includes conditional logic on occasion. If this is very complicated/would need considerable further development work, just let me know; I don’t mean to overly tax you!

    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array (
    	'key' => 'group_58498525e4216',
    	'title' => 'Seller',
    	'fields' => array (
    		array (
    			'layout' => 'horizontal',
    			'choices' => array (
    				'Business' => 'Business',
    				'Charity' => 'Charity',
    				'Individual' => 'Individual',
    			),
    			'default_value' => '',
    			'other_choice' => 0,
    			'save_other_choice' => 0,
    			'allow_null' => 0,
    			'return_format' => 'value',
    			'key' => 'field_55796aea16b81',
    			'label' => 'Owner status',
    			'name' => 'owner_status',
    			'type' => 'radio',
    			'instructions' => 'Horse owner status - business, charity or private individual. The status you select will be shown in your advert. Choose Business if buying and selling horses is your profession, Charity if you are a UK registered charity, and choose Individual if you are neither. This information will be shown on the advert',
    			'required' => 1,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    		),
    		array (
    			'default_value' => '',
    			'maxlength' => '',
    			'placeholder' => '',
    			'prepend' => '',
    			'append' => '',
    			'key' => 'field_557ee1588890f',
    			'label' => 'Business or charity name',
    			'name' => 'business_or_charity_name',
    			'type' => 'text',
    			'instructions' => 'Enter your business or charity name in full. This name will be shown on the advert',
    			'required' => 0,
    			'conditional_logic' => array (
    				array (
    					array (
    						'field' => 'field_55796aea16b81',
    						'operator' => '==',
    						'value' => 'Business',
    					),
    				),
    				array (
    					array (
    						'field' => 'field_55796aea16b81',
    						'operator' => '==',
    						'value' => 'Charity',
    					),
    				),
    			),
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'formatting' => 'none',
    		),
    		array (
    			'default_value' => '',
    			'min' => 1,
    			'max' => '',
    			'step' => '',
    			'placeholder' => '',
    			'prepend' => '',
    			'append' => '',
    			'key' => 'field_557ee1a0a325b',
    			'label' => 'Charity number',
    			'name' => 'charity_number',
    			'type' => 'number',
    			'instructions' => 'UK Registered Charity number',
    			'required' => 1,
    			'conditional_logic' => array (
    				array (
    					array (
    						'field' => 'field_55796aea16b81',
    						'operator' => '==',
    						'value' => 'Charity',
    					),
    				),
    			),
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    		),
    		array (
    			'default_value' => '',
    			'maxlength' => 20,
    			'placeholder' => '',
    			'prepend' => '',
    			'append' => '',
    			'key' => 'field_557edf8416bd0',
    			'label' => 'Evening phone number',
    			'name' => 'evening_phone_number',
    			'type' => 'text',
    			'instructions' => 'Evening contact telephone number. This information will be shown on the advert',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'formatting' => 'none',
    		),
    		array (
    			'default_value' => '',
    			'maxlength' => 20,
    			'placeholder' => '',
    			'prepend' => '',
    			'append' => '',
    			'key' => 'field_557edfc597bab',
    			'label' => 'Mobile phone number',
    			'name' => 'mobile_phone_number',
    			'type' => 'text',
    			'instructions' => 'Enter your mobile phone number. This information will be shown on the advert',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'formatting' => 'none',
    		),
    		array (
    			'default_value' => '',
    			'maxlength' => '',
    			'placeholder' => 'http://',
    			'prepend' => '',
    			'append' => '',
    			'key' => 'field_561d066811b09',
    			'label' => 'Website address',
    			'name' => 'website_address',
    			'type' => 'text',
    			'instructions' => 'Your charity or business website address starting http://',
    			'required' => 0,
    			'conditional_logic' => array (
    				array (
    					array (
    						'field' => 'field_55796aea16b81',
    						'operator' => '==',
    						'value' => 'Business',
    					),
    				),
    				array (
    					array (
    						'field' => 'field_55796aea16b81',
    						'operator' => '==',
    						'value' => 'Charity',
    					),
    				),
    			),
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'formatting' => 'none',
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'advert',
    			),
    		),
    	),
    	'menu_order' => 3,
    	'position' => 'normal',
    	'style' => 'seamless',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => 1,
    	'description' => '',
    ));
    
    endif;

    Thanks for your time taking a look at this for me.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, while the fields in ACF have similar structure to WPAdverts Forms they would need some custom programming in order to convert them into format that will be fully compatible with WPAdverts, so basically you would need to use adverts_form_load filter, to convert the current fields format into WPAdverts compatible fields and include them in the form.

    To be honest i am not really planning to make an integration with ACF as this would be duplicating functionality WPAdverts already have.

    Thread Starter sublimebydesign

    (@sublimebydesign)

    Hi, Does your Custom Fields add-on have conditional logic built in? I would need to present different fields depending on the category selected.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, currently the Custom Fields add-on does no support conditional logic, it is on our todo list, but right now i cannot tell when this will be ready.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to use ACF plugin with WPAdverts’ is closed to new replies.