Support

Account

Forum Replies Created

  • Correction, the $fieldId = $field["id"]; code gives the code of the main flexible field….How would I get the ‘id’ of each layout?

  • @hube2 Thanks for the reply.
    Using that code, I’ve set this up:

    add_filter(
        "acf/fields/flexible_content/layout_title",
        function ($title, $field, $layout, $i) {
            $fieldId = $field["id"];
            return $title_value
                ? "<strong>$title</strong> - <small>#$fieldId</small>"
                : "<small>$title</small>";
        },
        10,
        4,
    );

    which shows the field ID (ie: field_61a5392dc9480) in the title bar, which is great.

    I’m wondering if there is a way to not have the whole field collapse when clicking on the title bar? I’d like to be able to allow the admin to click/double-click on that field ID to copy it, but clicking it just collapses the field.

    Also, found an issue where when you collapse and reopen the field group it erases the new title – like it is there til you collapse then it disappears. I read some forum posts asking how to fix this and I didn’t find anything that worked. Is this possible to fix? Maybe its an ajax issue?

  • @hube2
    Here’s what I used to grab the fields.
    I had to run the loop outside the main flex loop or else it caused timeout errors.
    I also removed the first row of the loop since it was a True/False for checking if the nav should be present on the page.

    Since the “get_row_layout()” only grabs the slug of the row, I had to manually change some of the title, but then made it just work for any others that may show up.

    <?php if (have_rows("content_builder")) {
            $i = 0; ?>
        <section class="second-nav" id="second-nav">
            <div class="container">
                <div class="second-nav__menu" id="second-nav__menu">
                    <?php while (have_rows("content_builder")) {
                        the_row();
                        $i++;
                        if ($i != 1):
    
                            $flexField = get_row_layout();
                            $flexField = str_replace("_", "-", $flexField);
                            echo "<a href='#" . $flexField . "'>";
                            if ($flexField == "neighbourhood-overview") {
                                echo "Overview";
                            } elseif ($flexField == "neighbourhood-map") {
                                echo "What's Around";
                            } elseif ($flexField == "neighbourhood-stories") {
                                echo "Tenant Stories";
                            } elseif ($flexField == "show-other-properties") {
                                echo "Our Properties";
                            } elseif ($flexField == "other-neighbourhoods") {
                                echo "Our Neighbourhoods";
                            } else {
                                $flexField = str_replace(
                                    ["_", "-"],
                                    " ",
                                    $flexField,
                                );
                                echo ucwords($flexField);
                            }
                            echo "</a>";
                            ?>
    
        <?php
                        endif;
                    }
    } } ?>
  • @hube2

    I used this to make it work:

    <?php if (have_rows("content_builder")) {
            $i = 0; ?>
        <section class="second-nav" id="second-nav">
            <div class="container">
                <div class="second-nav__menu" id="second-nav__menu">
                    <?php while (have_rows("content_builder")) {
                        the_row();
                        $i++;
                        if ($i != 1):
    
                            $flexField = get_row_layout();
                            $flexField = str_replace("_", "-", $flexField);
                            echo "<a href='#" . $flexField . "'>";
                            if ($flexField == "neighbourhood-overview") {
                                echo "Overview";
                            } elseif ($flexField == "neighbourhood-map") {
                                echo "What's Around";
                            } elseif ($flexField == "neighbourhood-stories") {
                                echo "Tenant Stories";
                            } elseif ($flexField == "show-other-properties") {
                                echo "Our Properties";
                            } elseif ($flexField == "other-neighbourhoods") {
                                echo "Our Neighbourhoods";
                            } else {
                                $flexField = str_replace(
                                    ["_", "-"],
                                    " ",
                                    $flexField,
                                );
                                echo ucwords($flexField);
                            }
                            echo "</a>";
                            ?>
    
        <?php
                        endif;
                    } 
    }
    }?>
  • @amirami Does this still work for you?
    I’m getting the error “Uncaught TypeError: listing.addEventListener is not a function

    Plus with your code, how do you target the correct marker to open?

  • Not every field value, just the first level sub fields under the main flex field.

    So I have 5 sub fields (rows) that could show up on the page.

    I’m building it as sections, so each primary sub-field is a section of the site with its own sub-fields in it.

    I want to just link to each of those main sections with a button that is automatically made based on if the first level sub-field exists on the page.

    The “get_row_layout();” would be great if it had more than just the slug of the row.

    I just can’t find a way to grab the label of those rows.

  • Thanks for the quick response!
    So what i’m trying to do though, is i have 5 different flex subfields on a page, each with a bunch of their own sub fields i use to display content.

    I need to get the labels/names of each of those main 5 flex fields. The names are not a sub-field field, but are the actual labels of the sub-field if that makes sense.

    So like:

    Main_FlexFied
    |-> Overview Field.     <--I need this field's label
          -> Overview Sub 1
          -> Overview Sub 2
    |-> Image and text Field.   <--I need this field's label
          -> Image field
          -> Text field
    |-> Full text field      <--I need this field's label
          -> Text title
          -> Text content
  • @hube2 I’m still unsure how to get the actual label from that loop.

    If i call get_field(‘content_builder’); outside the “if (have rows…)’ part it gives me all all the data in that field, including rows that are not on the page, though the ‘label’ is in that array when I dump it.

    If i use it within the ‘have_rows’ and then try to do a foreach I get warnings like “Warning: Array to string conversion”

    Like if i set it up as:

    <?php if (have_rows("content_builder")) {
                while (have_rows("content_builder")) {
                    the_row();
                    $flexField = get_field("content_builder");
                    foreach ($flexField as $field) {
                        echo $field;
                        echo "<br>";
                    }
                }
            } ?>

    And if i var_dump $flexField inside the have_rows part, the label isn’t part of the array data. It seems to stay outside that loop.

  • @hube2 Yes no problem.

    So my page has a flexible field with 5 rows that I’m using.

    My goal is to have an in-page navigation menu with the nicename(aka label) of each of the rows with an in-page anchor link that will go to that section of the page.

    Since the pages could be changed, I can’t hardcode this, so I was hoping to set the code up to run through the rows that appear on a page, then set up links to each.

    If i use this code:

    <?php if (have_rows("content_builder")) {
        while (have_rows("content_builder")) {
            the_row();
            $flexField = get_row_layout();
            echo $flexField;
        }
    } ?>

    I get the slugs/name of each row.
    So and I know if i var_dump the main flexible field with get_field_object like:

    <?php if (have_rows("content_builder")) {
        while (have_rows("content_builder")) {
            the_row();
            $subs = get_field_object("content_builder");
            var_dump($subs);
        }
    } ?>

    i can see that the [label] fields are present in the array, “[“label”]=> string(23) “Neighbourhood: Overview”” but I cannot find a way to get it with the other row labels.

    Does that make more sense?

  • @revive Did you ever get this figured out?
    I’m using a repeater inside a flexible field too and I’m getting array errors with the ‘end’ code.

  • So here’s some insight into another part of this glitch.
    I’m running a staging site that has the normal wordpress debug=true on it for develelopmental purposes.
    Right now i have an error showing up in the header of my wp-admin for some other plugin that has update issues.

    But when I do an export of fields from the staging site – to transfer them to the live site – it comes up with an ‘Import file empty.” message.

    So when i look at the json file, the debug error that i had on my staging site is at the top of the json file, meaning its messing the whole file up and won’t upload.

    This is using the latest ACF Pro version, just FYI.

    Weird glitch, but hopefully this helps anyone else out.

    All i had to do is remove the text lines from the json file – up til the first ‘[‘ bracket, and then it would upload fine.

  • I just updated the site that started this forum to ACF Pro (3.5 years later!).

    I’m confirming that the code that @joshuaiz has here works. Updated code from my Nov 15, 2015 post above looks like this (different field group id):

    
    echo '<h3>Rates</h3>';
    $fields = acf_get_fields('48269');
    
    echo '<ul class="list-unstyled">';
    if( $fields )
    {
      foreach( $fields as $field )
      {
        $value = get_field( $field['name'] );
        if ($field['choices']){
          $map = array(
           'yes' => '<i class="icon-ok"></i>'       
           );
          $value = $map[ $value ];
        } else {
        }
        if( $value && $value != 'no') {
          echo '<li>' . $field['label'] . '&nbsp;' . $value . '</li>';
      }
    }
    }
      echo '</ul>';
    
  • @james We basically want our users who own businesses listed on our website to first have to pick a parent term, then get to see the possible child terms in the editor.
    So we could have ‘restaurants’ and ‘hotels’ as parent terms, then once one is selected, they can then see the child terms. So if they pick ‘restaurant’ first, then the second select should show its children, like ‘cafe’ or ‘pizzeria’.
    So a two-level dropdown would be best.

    @ionut I’ve never heard of the chain selector before…how would i set that up? Do you have a reference for that?

  • Found my own answer!

    The “Show this field group if” Post Taxonomy is XXX works.
    Don’t know how I missed that before.

    Solved!

  • Hey Everyone! Glad this conversation is expanding.
    I’ve run into a new problem with this code.

    It seems like I can’t add conditions to this code within the main If statement, to not display if empty.

    Here’s the issue. I have a header tag above this field group that I want to remove if there are no entries. I just can’t seem to get the code right.
    Here’s what I have now:

      $group_ID = 13249;
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    
    if( $fields )
    {
    echo '<div class="col-sm-6">';
    echo '<h3>Rates:</h3>'; //------I want to remove this line if field is empty, but it keeps appearing
        echo '<ul class="list-unstyled">';
      foreach( $fields as $field_name => $field )
      {
        $value = get_field( $field['name'] );
        if ($field['choices']){
          $map = array(
           'yes' => '<i class="icon-ok"></i>'       
           );
          $value = $map[ $value ];
        } else {
        }
        if( $value && $value != 'no') {
          echo '<li>' . $field['label'] . '&nbsp;' . $value . '</li>';
      }
    }
      echo '</ul>';
    echo '</div>';
    }

    So i need that h3 tag to not show up. What i found is that even when empty, the $fields variable sees an array (just echoing $fields shows ‘array’). So there is no way to say if ’empty’.

    Thoughts?

  • Hi Lucas,

    Does this code just print the city in the front end in the posts with an address field? Or how would you call it? I’m looking for the same thing I think: to just extract the city from the google maps field. With your function above, how would I call it within a custom post type?

    Thanks!!!

  • That’s great! Seems to work perfectly!

    Thank you!

  • Ok, so there is a hack way of doing what I want.

    In taxonomy.php i modified line 1020 from this:

    		// append
    		$output .= '<li data-id="' . $term->term_id . '"><label><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>' . $term->name . '</span></label>';
    				
    	}

    to this:

    // append
    		$output .= '<li data-id="' . $term->term_id . '"><label><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>'. $term->slug .'-' . $term->name . '</span></label>';
    				
    	}

    adding in the ‘$term->slug’ in the label span.

    So now a term looks like:

    1132-Forest Nurseries and Gathering of Forest Products

    With 1132 being the slug.

    This isn’t a good solution, since it could get overwritten, so just need to find out how to make that work….
    Especially because I have a second Taxonomy field (different taxonomy) that I don’t want the slug to show up on….

  • Hey Jonathan

    Ok, we could see how the multi-select works.
    What filter would be used to modify this to include the slug?

    And to modify my first post, we only need the one set of terms to show.

    Here’s the filter from the documentation. Is this what we use?

    <?php
    
    function my_taxonomy_query( $args, $field, $post_id ) {
        
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        
        
        // return
        return $args;
        
    }
    
    add_filter('acf/fields/taxonomy/query', 'my_taxonomy_query');
    
    ?>
  • Hi John

    Ok thanks for the info. We’re going to try a few things and I’ll reply with what finally works!

  • No it doesn’t give any info on that. The basic problem I found is that it will import the address, and it shows up in the ACF Google Map field, but since i’m not importing any coordinates, it doesn’t actually make the map itself do anything. The data is just in the address field above the map in the back end.

    So essentially its there, and just needs something to ‘trigger’ it (aka click on the address, hit enter, and it finds it fine).
    But I need something to do this automatically, so we don’t have to go into 7000 posts and do it.

    WPAI support did say this:

    currently there is no geocoding feature included on the import of ACF Google Map fields. You would need to directly import the latitude and longitued values if you want the map to be automatically rendered without any manual trigger. Entering just an address is not enough to render a map.

    You could automate this by creating a custom php function that calls on the geocoding API of your choice (most commonly the Google Maps API) and get the lat/long details based on your street address.

    But i have no idea how to event start looking into that.

  • Hi john

    We are using WP All Import to import everything. We need to use this plugin because the client wants to update the listings often via csv upload and this plugin allows that, as well as working with ACF fields.

    Just doesn’t trigger the map.

  • Having issues between revisionary plus and acf too.
    For some reason if you edit a field, then save, you see the changes on the front end, but as soon as you leave the editing page, it reverts back to a previous version.

    Works fine when revisionary plus is turned off, but I need both ACF and revisionary working on the site…

    Any updates on this???

  • So after much research and testing, I found that there is a weird conflict between ACF and a plugin called Revisionary. Not sure why yet, as I don’t know how to look into what conflicts, but at least I know.

    Problem is I really need Revisionary to work on the site as well to limit author’s editing.

    If anyone has a solution to this, I’d love to hear it.

Viewing 25 posts - 1 through 25 (of 44 total)