Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Edit: I also tried to use ACF JSON, but without success. I’ve created a directory named acf-json, and after saving the field-group a new file was written to the directory. But there was no time-improvement, and the number of queries didn’t decrease.

  • I’m not sure what changed but I decided to try some code I’d been working with previously and it has decided to work today (aggravating but I’ll take what I can get). For anyone in a similar boat, this is what I did:

    <?php query_posts(array(
            'post_type' => 'sponsor',
            'showposts' => -1,
    		'meta_key' => 'child_info_child_idnum',
    		'orderby' => 'meta_value',
    		'order' => 'ASC',
        	'post_status' => 'publish'));
    
    			if ( have_posts() ) :?>
    				
    				<ul id="spo_kids">
    					<?php while ( have_posts() ) : the_post(); 
    
    						if( have_rows('child_info') ): 
    					?>
    
    								<ul>
    
    										<?php while( have_rows('child_info') ): the_row(); 								$child_image = get_sub_field('child_picture');
     ?>
    
    															<li>
    																<div>
    
    																		<img src="<?php echo esc_url( $child_image['url'] ); ?>" alt="<?php echo esc_attr( $child_image['alt'] ); ?>" />
    																	<?php echo '<h5>';
    																		echo the_title();
    																		echo '</h5>';
    
    																		echo '<span class="c-dob">';
    																			echo 'DOB: ';
    
    																				if ( get_sub_field('birthday') ):
    																					echo the_sub_field('birthday');
    																				else: echo 'Unknown'; endif; 
    
    																		echo '</span>';
    
    																		if ( get_sub_field('date_verified') ):
    																			echo '<span class="c-verified">';
    																				echo 'Verified: ';
    																				echo the_sub_field('date_verified');
    																			echo '</span>';
    																		else: endif;
    
    																	?>
    																				<a class="spo-links" href="<?php the_permalink(); ?>#spo_form" />
    																					<?php if ( get_sub_field('currently_sponsored') == 'Special Need' ): ?>
    																						Special Need
    																					<?php else: ?>
    																						Sponsor Now
    																					<?php endif; ?>
    																				</a>
    																				<a class="spo-links" href="<?php the_permalink(); ?>" />Learn More</a>
    																</div>
    															</li>
    
    										<?php endwhile; ?>
    
    								</ul>
    
    <?php endif; endwhile; endif; ?>
  • 
    // PHP
    // register a script
    // see https://developer.wordpress.org/reference/functions/wp_register_script/
    wp_register_script($handle, $src, $deps, $ver, $in_footer);
    
    // build JS object
    // here I am assuming I have a repeater with 2 sub fields
    // Let's assume they are two date fields
    
    // initialize my object as an array
    // it will hold the rows of the repeager
    $object = array();
    
    if (have_rows('repeater')) {
      while (have_rows('repeater')) {
        the_row();
        // add row to array
        $object[] = array(
          'start_date' => get_sub_field('start_date'),
          'end_date' => get_sub_field('end_date')
        );
      }
    }
    
    // localize script
    $object_name = 'my_js_object';
    wp_localize_script($handle, $object_name, $object);
    
    // enqueue the script
    wp_enqueue_script($handle);
    
    
    // JS File
    if (my_js_object.length > 0) {
      for (i=0; $i<my_js_object.length; i++) {
        var row = my_js_object[i];
        // do something with the row
        console.log(row['start_date'];
        console.log(row['end_date'];
    
        // the above lines could also use this syntax
        console.log(row.start_date);
        console.log(row.end_date);
      }
    }
    
  • Thanks John for sharing the resources..

    How would I pass a repeater subfield data into the localize script?

    Edit:
    Solved my own question:
    https://allisontarr.com/2017/09/15/function-wp_localize_script/

    You dont need the .descriptor_list on acf_vars.list_parent

  • Typo on this line

    
    if (empty($field('value'])) {
    

    should be

    
    if (empty($field['value'])) {
    

    Can’t see typos easily here when adding code. There are other typos as well, I did not always spell references correctly. Sorry about these, I was just typing out a quick example and sometimes it happens.

    All of the code should go in functions.php. Automating things can sometimes be difficult. You have to way the time it takes to do the automation vs how much time it will save.

  • +1 Looking for exactly this too. Using acf_form with a Gallery field – need to keep users in the front end, but the ‘Edit Image’ link takes you to the backend. With my specific requirement just being able to rotate and resave an image via the front end would be enough.

  • Sometimes adding scripts / libraries to Gutenberg Editor (backend) cause serious problems. In case someone else have problems you can simply use if(! is_admin()) inside enqueue_assets, like so:

    ` ‘enqueue_assets’ => function () {
    // Load assets only on frontend – the libs cause unwanted sideeffects in gutenberg
    if(! is_admin()){
    wp_enqueue_script(‘filtrify’, get_stylesheet_directory_uri() . ‘/libraries/stuff/js/foo.min.js’, array(‘jquery’), null, true);
    }
    },

  • Sometimes adding scripts / libraries to Gutenberg Editor (backend) cause serious problems. In case someone else have problems you can simply use if(! is_admin()) inside enqueue_assets, like so:

    ` ‘enqueue_assets’ => function () {
    // Load assets only on frontend – the libs cause unwanted sideeffects in gutenberg
    if(! is_admin()){
    wp_enqueue_script(‘filtrify’, get_stylesheet_directory_uri() . ‘/frontend_libraries/filtrify/js/’ . foundationpress_asset_path(‘filtrify.min.js’), array(‘jquery’), null, true);
    wp_enqueue_script(‘video-modal’, get_stylesheet_directory_uri() . ‘/frontend_libraries/modal-video/js/’ . foundationpress_asset_path(‘jquery-modal-video.min.js’), array(‘jquery’), null, true);
    wp_enqueue_script(‘video-collection’, get_stylesheet_directory_uri() . ‘/frontend_libraries/webkswct-base/js/’ . foundationpress_asset_path(‘webkswct.gb_video_collection.js’), array(‘jquery’), null, true);
    wp_enqueue_style(‘video-modal-styles’, get_template_directory_uri() . ‘/frontend_libraries/modal-video/css/modal-video.min.css’, false, ‘1.0.0’);
    }
    },

  • Its Oct, 2020 now…
    I wish to have the date set to today ONLY upon creation.
    BUT, ACF pro latest (5.9.1) seems to ignore it.
    Even when I modify the date – it will DISPLAY today date
    And will retain the original in the database (ie. not updating…)
    Here is my code:

    add_filter('acf/load_field/name=YOUR_FILED_NAME', 'my_acf_default_date');
    function my_acf_default_date($field) {
      if (isset($field['default_value']) && $field['default_value'] != "") 
         return $field; // do not change...
      $field['default_value'] = date('Ymd');
      return $field;
    }

    Any idea how to manage this behavior is highly appreciated. Thanks!

  • I am using elementor but i was using the ACF shortcode like you use it in wordpress so elementor isnt a problem.

    Im new to ACF, so i was trying to understand how to create a clickable link. Looking at the field types in ACF, URL looks like the one you use for someone to fill in a url and then on the front end it appears for someone to click on.
    But looking at your answer on the post i linked, it seems otherwise, plus your answer saying…

    “Just a little off topic, but I don’t use URL fields much. I basically always use a text field. URL fields are too limiting. I want to allow users to enter any valid href value, so I use a text field and then add custom validation to to it.”

    So reading the original post and then your reply to it, sounds like you use a text field with some custom code to allow users to fill in a url in the backend for it to display on the frontend of the website and allow visitors to click it, am i right in thinking this?

  • <?php
    $text = get_field('character_overview_title');
    if (emtpy($text)) {
      $text = get_the_title();
    }
    ?>
    
    <div class="character-overview" id="overview">
        <h2><?php echo $text; ?> Overview</h2>
        <p class="overview-description"><?php the_field( 'character_overview_description' ); ?></p>
    </div>

    Breaks the site for some reason.

  • To be honest, I’m a little confused whey your are doing this

    
    $field = get_field_object( 'custom_field) );
    $value = get_post_meta( $post_id, 'custom_field', true );
    echo $field['choices'][ $value ];
    

    Why get the field object, then get the meta value and then output echo the label.

    Set the field to either return the label or to return and array with value/label and then use

    
    // set to return label
    the_field('custom_field')
    

    or

    
    // set to return both
    $value = get_field('custom_field');
    echo $value['lable'];
    

    back to your question. If the values choices are not being set when you call get_field_object() then that means that your filter is not being called. Where/in what file/when is your load filter being called?

  • What you need to do is create an WP option that holds the value last used.

    
    // on WP init create an option value if it does not exist
    // this code can be deleted after the option is created
    // or it can be left alone
    add_action('init', 'create_my_reference_options');
    function create_my_reference_options() {
      $reference = get_option('reference_field_counter', false);
      if (!$reference) {
        update_options('reference_field_counter', 12345);
      }
    }
    

    Having a counter in place you can then use an acf/prepare_field filter to set the value if it is not set

    
    add_filter('acf/prepare_field/name=reference_field_name', 'set_reference_value');
    function set_reference_value($field) {
      if (empty($field('value'])) {
        $reference = intval(get_option('reference_field_counter'));
        $reference++;
        $field['value'] = $refefence;
        update_options('reference_field_counter', $reference);
      }
      return $field;
    }
    

    Note that this will continue to increment the reference number each time the page is loaded even if the post is not saved and may leave gaps in your numbering system. If this in not the case then it gets more complicated. Rather than using an option you would instead need to do a query in the prepare_field filter to get the post with the highest number and then you that value to set the new one. But this also has drawbacks. In the instance where multiple posts are created at the same time then it is likely that numbers will be repeated. I doubt there is a full-proof method.

  • Your question is about changing the way the builder you are using does whatever it does. You will need to contact them about how to alter that.

  • When I have these type of question I go into ACF admin and I crate a similar field set the way I want it to be and then export that to PHP to see what the code should look like.

    A repeater is just like any other field except it has an index named “sub_fields” that is an array of fields defined in the same way as they would be when not in a repeater.

  • The issue is that you’re using elementor. I do not use elementor or any other tool/plugin that does my coding for me. If I want to use a field as a link I open the php file where it will be used and add something like

    
    <a href="<?php the_field('my-url-field'); ?>">Link Text Here</a>
    

    ACF does not have anything built in that will do this for me.

    When using another tool to do coding for you then any questions related to how to use a particular field should be addressed to the author of that tool.

    As far as using a text field or some other type of field, I do not know how the person in the other thread managed to use a text field, because, again, I don’t use elementor. You might want to try posting a comment in that thread and asking him for more information about how it was done. He does supply a link to get more information from.

  • Hi

    Quick question where do i add the php to? I have got the attactment part working in the image media serttings but its not clicking through to the custom link.

    thanks

    Danny

  • $field = get_field_object( 'custom_field' );
    echo '<pre>'; print_r($field['choices']); echo '</pre>';
    //Displays
    Array
    (
        [ID] => 177
        [key] => field_5dcf111592fe2
        [label] => Custom Color
        [name] => custom_field
        [prefix] => acf
        [type] => select
        [value] => blue
        [menu_order] => 0
        [instructions] => 
        [required] => 0
        [id] => 
        [class] => 
        [conditional_logic] => Array
            (
                [0] => Array
                    (
                        [0] => Array
                            (
                                [field] => field_5dcf0ad861cf1
                                [operator] => ==
                                [value] => background
                            )
    
                    )
    
            )
    
        [parent] => 176
        [wrapper] => Array
            (
                [width] => 
                [class] => 
                [id] => 
            )
    
        [choices] => Array
            (
               [Blue] => Blue
               [Red] => Red
               [Green] => Green
               [Yellow] => Yellow
               [White] => White
               [Pink] => Pink
            )
    
        [default_value] => Array
            (
            )
    
        [allow_null] => 1
        [multiple] => 0
        [ui] => 0
        [return_format] => value
        [ajax] => 0
        [placeholder] => 
        [_name] => background
        [_valid] => 1
    )
    $value = get_post_meta( $post_id, 'custom_field', true );
    echo $value;
    //Displays
    blue

    I see the intended choices when I go into edit the custom fields. The select menu shows me:

    blue : Blue
    red : Red
    green : Green
    yellow : Yellow
    white : White
    pink : Pink
  • ok, after some reading i think what i need to do is make it as a repeater field to display as an accordion in my page builder, but i still cant get it to show in my template:

    json:

    [
        {
            "key": "group_553b8b2752aba",
            "title": "Page Builder",
            "fields": [
                
                {
                    "key": "field_553b8b4fc8c3b",
                    "label": "Page Sections",
                    "name": "acf_page_builder",
                    "type": "flexible_content",
                    "instructions": "",
                    "required": 1,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "button_label": "Add Section",
                    "min": "",
                    "max": "",
                    "layouts": [
                        					
    					{
                            "key": "561538dcw4334t",
                            "name": "accordion_row",
                            "label": "Accordion Row",
                            "display": "row",
                            "sub_fields": [
                               {
    								"key": "field_5f95ee9195280",
    								"label": "Accordion",
    								"name": "accordion",
    								"type": "repeater",
    								"instructions": "",
    								"required": 0,
    								"conditional_logic": 0,
    								"wrapper": {
    									"width": "",
    									"class": "",
    									"id": ""
    								},
    								"collapsed": "",
    								"min": 0,
    								"max": 0,
    								"layout": "table",
    								"button_label": "",
    								"sub_fields": [
    									{
    										"key": "field_5f95eebb95281",
    										"label": "Accordion Title",
    										"name": "accordion_title",
    										"type": "text",
    										"instructions": "",
    										"required": 0,
    										"conditional_logic": 0,
    										"wrapper": {
    											"width": "",
    											"class": "",
    											"id": ""
    										},
    										"default_value": "",
    										"placeholder": "",
    										"prepend": "",
    										"append": "",
    										"maxlength": ""
    									},
    									{
    										"key": "field_5f95eece95282",
    										"label": "Accordion Content",
    										"name": "accordion_content",
    										"type": "wysiwyg",
    										"instructions": "",
    										"required": 0,
    										"conditional_logic": 0,
    										"wrapper": {
    											"width": "",
    											"class": "",
    											"id": ""
    										},
    										"default_value": "",
    										"tabs": "all",
    										"toolbar": "full",
    										"media_upload": 1,
    										"delay": 0
    									}
    								]
    							}
    
                            ],
                            "min": "",
                            "max": ""
                        },
                        
                        
                    ]
                }
            ],
            "location": [
                [
                    {
                        "param": "post_type",
                        "operator": "==",
                        "value": "post"
                    }
                ],
                [
                    {
                        "param": "page_template",
                        "operator": "==",
                        "value": "page-templates\/full-width.php"
                    }
                ]
            ],
            "menu_order": 0,
            "position": "normal",
            "style": "default",
            "label_placement": "top",
            "instruction_placement": "label",
            "hide_on_screen": [
                "the_content"
            ],
            "active": 1,
            "description": ""
        }
    ]

    PHP:

    <?php
    
    Class ACF_Page_Builder {
    
    	/**
    	 * Check if Advanced Custom Fields is Active
    	 * @var (Boolean)
    	 */
    	private $acf_active;
    
    	/**
    	 * Check if Simple Contact Forms is Active
    	 * @var (Boolean)
    	 */
    	private $scf_active;
    
    	/**
    	 * The final HTML to return with the section data inluded
    	 * @var String
    	 */
    	private $html;
    
    	/**
    	 * Formats that can be used in the acfs_add_support and acfs_remove_support functions
    	 * @var Array
    	 */
    	public $supported_formats;
    
    	/**
    	 * Variable to declare whether we should use Bootstrap or not
    	 * @var Boolean
    	 */
    	private $use_bs;
    
    	/**
    	 * Constructor of the class. Sets some default values
    	 */
    	function __construct() {
    
    		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
    		$this->acf_active = is_plugin_active( 'advanced-custom-fields/acf.php' ) || is_plugin_active( 'advanced-custom-fields-pro/acf.php' );
    
    		$this->scf_active = is_plugin_active( 'simple-contact-forms/simple-contact-forms.php' );
    
    		$this->supported_formats = array('post_type', 'page_template');
    
    		$this->use_bs = function_exists('get_field') ? get_field('acfpb_use_bootstrap') : false;
    
    	}
    
    	/**
    	 * Enqueue the styles and scripts for the public
    	 */
    	public function enqueuePublic() {
    
    		wp_enqueue_style( 'acfpb-public', plugin_dir_url( __FILE__ ) . '../public/css/acfpb_styles.css', false, NULL, 'all' );
    
    	}
    
    	/**
    	 * Enqueue the styles and scripts for the admin
    	 */
    	public function enqueueAdmin() {
    
    	}
    
    	/**
    	 * Retrieves all the section HTML 
    	 * @param  String $name The slug used for the sections. Is 'sections' by default
    	 * @return String       The final HTML
    	 */
    	public function getSectionsHTML( $name, $post_id ) {
    
    		if( !$this->acf_active ) return '';
    
    		if( have_rows( $name, $post_id ) ):
    
    			$s = 1;
    
    			$this->html = '<div id="acfpb_sections">';
    
    			while ( have_rows( $name, $post_id ) ) : the_row();
    
    				$layout = get_row_layout();
    
    				if( method_exists(get_class(), 'getSection_' . $layout ) ) :
    
    					$id = 'section_' . $s;
    
    					$class = 'acfpb_section section-' . $layout;
    
    					$style = get_sub_field('bg') ? 'background-color:' . get_sub_field('bg') : '';
    
    					$contained = (boolean) get_sub_field('contained', false);
    
    					if( !$this->use_bs && $contained ) $contained = false;
    
    					$wrapper = get_sub_field('wrapper_class');
    
    					$this->html .= '<div id="' . $id . '" class="' . $class . '" style="' . $style . '"><div class="sectionwrap">';
    
    						if( $contained ) $this->html .= '<div class="container">';
    
    							if( $contained ) $this->html .= '<div class="row">';
    
    								if( $wrapper !== '' ) $this->html .= '<div class="' . $wrapper . '">';
    
    									$this->html .= $this->{'getSection_' . $layout}();
    
    								if( $wrapper !== '' ) $this->html .= '</div>'; // Wrapper finish
    
    							if( $this->use_bs ) $this->html .= '<div class="clearfix"></div>';
    
    							if( $contained ) $this->html .= '</div>'; // Row finish
    
    						if( $contained ) $this->html .= '</div>'; // Container finish
    
    					$this->html .= '</div></div>'; // Section finish
    
    					$s++;
    
    				endif;
    
    			endwhile;
    
    			$this->html .= '</div>'; // Main Wrapper finish
    
    			return $this->html;
    
    		else :
    
    			return '';
    
    		endif;
    
    	}
    
    	/**
    	 * Admin function to add the fields to wordpress. Also figures out where to show them based on the acfs_add_support and acfs_remove_support functions
    	 */
    	public function addFieldsToWP() {
    
    		if( !$this->acf_active ) return false;
    
    		if( function_exists('acf_add_local_field_group') ) {
    
    			// Get the exported field data
    
    			$json = file_get_contents( plugin_dir_path(__FILE__) . '../admin/acf-fields.json' );
    
    			$json_to_php = json_decode( $json, true );
    
    			$acf_fields_array = $json_to_php[0]['fields'];
    
    			// Check if SCF is included or leave it out of the list of fields if not
    
    			if( !$this->scf_active ) {
    
    				foreach ($acf_fields_array[1]['layouts'] as $key => $data) {
    					
    					if( $data['name'] === 'simple_contact_forms' ) {
    
    						unset( $acf_fields_array[1]['layouts'][$key] );
    
    						break;
    
    					}
    
    				}
    
    			}
    
    			// Create the rest of the field group
    
    			$meta = array(
    				'key' 					=> 'group_553b8b2752aba_pb10192283',
    				'title' 				=> 'Page Builder',
    				'fields' 				=> $acf_fields_array,
    				'menu_order' 			=> 10,
    				'position' 				=> 'normal',
    				'style' 				=> 'default',
    				'label_placement' 		=> 'top',
    				'instruction_placement' => 'label',
    				'hide_on_screen' 		=> array (),
    				'location' 				=> array(),
    				'active'				=> 1,
    				'description' 			=> '',
    			);
    
    			// Filter to get the locations
    
    			$location = apply_filters( 'acfpb_set_locations', array() );
    
    			$l = 0;
    
    			foreach ($this->supported_formats as $format) {
    
    				if( !isset($location[$format]) || empty($location[$format]) ) continue;
    					
    				$meta['location'][$l] = array();
    
    				foreach ($location[$format] as $place) {
    
    					$meta['location'][$l][] = array(
    						'param' 	=> $format,
    						'operator' 	=> '==',
    						'value' 	=> $place,
    					);
    
    					$l++;
    
    				}
    
    			}
    
    			acf_add_local_field_group($meta);
    
    		}
    
    	}
    
    		
    	/**
    	 * Get the Accordion section.
    	 * @return String Final string of this section
    	 */
    	private function getSection_accordion_row() {
    
    		if( have_rows('accordion') ):
    	$i = 1; // Set the increment variable
    	
    	echo '<div id="accordion">';
     	
     	// loop through the rows of data for the tab header
        while ( have_rows('accordion') ) : the_row();
    		
    		$header = get_sub_field('accordion_title');
    		$content = get_sub_field('accordion_content');
    
    	?>
    		
    		<div class="card">
    		    <div class="card-header" id="heading-<?php echo $i;?>">
    		      <h5 class="mb-0">
    		        <button class="btn btn-link" data-toggle="collapse" data-target="#collapse-<?php echo $i;?>" aria-expanded="true" aria-controls="collapse-<?php echo $i;?>">
    		          <?php echo $header; ?>
    		        </button>
    		      </h5>
    		    </div>
    		
    		    <div id="collapse-<?php echo $i;?>" class="collapse" aria-labelledby="heading-<?php echo $i;?>" data-parent="#accordion">
    		      <div class="card-body">
    		        <?php echo $content; ?>
    		      </div>
    		    </div>
    		 </div>    
    		
    		
    	<?php $i++; // Increment the increment variable
    		
    	endwhile; //End the loop 
    	
    	echo '</div>';
    
    else :
    
        // no rows found
        echo 'Come back tomorrow';
    
    endif;
    
    	}
    
    }
  • ok, so i have managed to get an accordion to display in my page editor, but not sure if this will close the accordion properly? and how to display this in my page builder php properly?

    json for accordion:

    		{
                            "key": "561538dcw4334t",
                            "name": "accordion_row",
                            "label": "Accordion Row",
                            "display": "block",
                            "sub_fields": [
                                {
    								"key": "field_5f90caa048f59",
    								"label": "accordion-open",
    								"name": "",
    								"type": "accordion",
    								"instructions": "",
    								"required": 0,
    								"conditional_logic": 0,
    								"wrapper": {
    									"width": "",
    									"class": "",
    									"id": ""
    								},
    								"open": 0,
    								"multi_expand": 0,
    								"endpoint": 0
    							},
    							{
    								"key": "field_5f95e677d32d0",
    								"label": "Accordion Title",
    								"name": "accordion_title",
    								"type": "text",
    								"instructions": "",
    								"required": 0,
    								"conditional_logic": 0,
    								"wrapper": {
    									"width": "",
    									"class": "",
    									"id": ""
    								},
    								"default_value": "",
    								"placeholder": "",
    								"prepend": "",
    								"append": "",
    								"maxlength": ""
    							},
    							{
    								"key": "field_5f95e686d32d1",
    								"label": "Accordion Content",
    								"name": "accordion_content",
    								"type": "wysiwyg",
    								"instructions": "",
    								"required": 0,
    								"conditional_logic": 0,
    								"wrapper": {
    									"width": "",
    									"class": "",
    									"id": ""
    								},
    								"default_value": "",
    								"tabs": "all",
    								"toolbar": "full",
    								"media_upload": 1,
    								"delay": 0
    							},
    							{
    								"key": "field_5f90cab348f5a",
    								"label": "accordion-end",
    								"name": "",
    								"type": "accordion",
    								"instructions": "",
    								"required": 0,
    								"conditional_logic": 0,
    								"wrapper": {
    									"width": "",
    									"class": "",
    									"id": ""
    								},
    								"open": 0,
    								"multi_expand": 0,
    								"endpoint": 1
    							}
    
                            ],
                            "min": "",
                            "max": ""
                        },

    PHP in page builder plugin to display the accordion:

    	private function getSection_accordion() {
    
    		$blocks = get_sub_field('accordion_row');
    
    		$html = '';
    
    		if( count($blocks) > 0 ) :
    
    	        foreach($blocks as $block) {
    
    	            $html .= '<div class"accordion-title">';
    
    	                $html .= $block['accordion-title'];
    
    	            $html .= '</div>';
    				
    				$html .= '<div class"accordion-content">';
    
    	                $html .= $block['accordion_content'];
    
    	            $html .= '</div>';
    
    	        }; 
    
    		endif;
    
    		return $html;
    
    	}
  • When I dump out the value for the $field the choices are are the original values that was inserted into the field, and not the filtered values that are being brought in dynamically.

    I am not sure if it matters or not, but I am trying to display the fields as custom columns in my custom post type.

    function custom_column( $column, $post_id ) {
            
        switch ( $column ) {
                
    		case 'custom_title':
                
    			$field = get_field_object( 'custom_field) );
    			$value = get_post_meta( $post_id, 'custom_field', true );
    			echo $field['choices'][ $value ]; //This returns an Undefined index and the index value is not in the $field variable.
    
    			break;
                
            default:
                
                break;
    
        }
    }
    add_action( 'manage_custom_posts_custom_column', 'custom_column', 10, 2);

    And to load my custom field:

    function acf_custom_field_choices( $field ) {
        
        // reset choices
        $field['choices'] = array();
    
    	$args = array(
    		'post_type'  => 'custom_post_type',
    		'parent'     => 0
    	);
    	
    	$pages = get_pages( $args );
    	
    	foreach ( $pages as $page ) {
                
    		// vars
    		$value = $page->post_name;
    		$label = $page->post_title;
    
    		// append to choices
    		$field['choices'][ $value ] = $label;
            
        }
    
        // return the field
        return $field;
        
    }
    
    add_filter('acf/load_field/name=custom_field','acf_custom_field_choices', 10, 1);

    I am not sure if my loading sequence or priority of the filter and/or action matters.

  • You cannot use shortcodes for the href value. This will not work.

    
    <a href="[acf field="website"]">[acf field="website"]</a>
    

    You can also not use PHP as you’ve done in your code.

    Neither of these methods are supported by WP.

    The only way to do this is to create a custom shortcode that outputs the entire link.

  • Then I would probably do something like

    
    $text = $row['text'];
    if (!empty($row['link'])) {
      $text = '<a href="'.$row['link'].'">'.$text.'</a>';
    }
    echo $text;
    
  • This cannot be done using just ACF unless you build your own shortcode. You may want to direct your question at elementor. But I can’t say because there’s not enough information about how where or how you are attempting to output the URL.

  • 
    <?php
    $rows = get_field('home' ); //get all rows
    shuffle ($rows); //randomize rows
    if($rows) {
    	foreach($rows as $row) { //print rows 
    if (!empty($row['link'])) {
    
    ?>
    		<div class="home-box">
    			<?php
    			echo '<a href="';
    			echo $row['link'];
    			echo '">';
    			echo $row['text'];
    			echo '</a>'
    			?>
    	</div>
    	<?php
    } // end if link !empty
    	}
    }
    
    ?>
    
Viewing 25 results - 6,326 through 6,350 (of 21,337 total)