Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • 
    <?php
      $group_ID = 30109;
      $fields = array();
      $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    
      $exclude = array('field_5919f45752917', 'field_5919f46252918', 'field_5919f46a52919');
    
      if ($fields) {
        echo '<div class="col-sm-6">';
        echo '<h3>Description:</h3>';
        echo '<ul class="list-unstyled">';
        foreach ($fields as $field_name => $field) {
          if (in_array($field['key'], $exclude)) {
            continue;
          }
          $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>';
           }
        } // end foreach
        echo '</ul>';
        echo '</div>';
      } // end if fields
    ?>
    
  • The reason that I think your having difficulty doing what your trying to do is that you’re trying to group the posts after you get the posts.

    get posts => look at field and => group the posts by the field

    Once you’ve gotten the posts and started looping through them it is too late to group them in a specific order. You need to set the order/grouping before you get them.

    To compound things further, your not only want them ordered by this field, but you also want them ordered in the same order as the field choices set in the ACF field. Depending on what this field holds it may not even be possible to order them.

    So, a couple of questions.

    Are the choices set in the field choices in alphanumeric order?

    Can the wheel_section field have more than one value?

  • You didn’t include the screen shots.

    The main questions I would have in any case have nothing to do with what your field looks like or what your code looks like.

    1) How is the content for these fields being added? Is all of the content being added by actually editing the posts in the admin? Or, is there some type of import process being used to add the content?

    2) Assuming that by drop down you mean a select field, does this field allow multiple selections or only one selection?

  • Local JSON files increase the speed of your site by loading field groups and field definitions from the file instead of making database query.

    The local JSON files will not effect the displaying of the content of those fields that is saved to a post whether they are shown with shortcodes or using functions like get_field() or the_field() in PHP code. The same number of db queries will be done in either case. The only difference is that there are a couple of extra layers of PHP processing that needs to be done. The extra PHP code/function calls should not create a noticeable difference in performance. I can’t give you any testing data, but it would probably takes many thousands of shortcode calls to effect the load time of a single page.

  • I’m having what I think is a similar issue with ACF PRO versions >= 5.5.0.

    At present, I have front-end ajax submission forms that work well with ACF PRO 5.4.8. On the js end, the script first checks for validation errors via the acf/validate_save_post action, and if the returned object from that call includes data.valid: 1 I go on to call an action attached to acf_form_head that updates field values.

    However, with versions >= 5.5.0, no data/object is returned from my first acf/validate_save_post call.

    Here’s an example of an object that’s getting sent to acf/validate_save_post in my jquery ajax call:

    
    {
      acf[_validate_email]:"",
      acf[field_5745dbdfc7e0b]:"Foo Bar",
      action:"acf/validate_save_post",
      _acfchanged:"1",
      _acfform:"Mm0rU0VT[abbreviated]",
      _acfnonce:"7ba82c905c"
    }
    

    And here’s the response that call gets using ACF PRO < 5.5.0:

    
    {
      data:{
        errors:0,
        valid:1
      },
      success: true
    }
    

    Any ideas about why I’m no longer getting a response to this call would be very much appreciated!!!

    Thanks,
    Ethan

  • I figured this out. In case anyone else wants to know…

    <div class="sponsors">
    <?php
    global $post;
    $the_query = new WP_Query( array(
        'post_type' => 'contestants',
        'tax_query' => array(
        array(
          'taxonomy' => 'year_type',
          'field' => 'slug',
          'terms' => array( 'term_1', 'term_2', 'term_3' )
        )
      ))
    ) ;
    
    if($the_query->have_posts()){
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
    if( have_rows('sponsors', $post->ID) ):
        // loop through the rows of data
    
        while ( have_rows('sponsors') ) : the_row();
    
            // display a sub field value
            $image = get_sub_field('sponsor_logo');
            $url = get_sub_field('sponsor_url');
            $name = get_sub_field('sponsor_name');
    
            ?>
            <div class="sponsor"><a href="<?php echo $url; ?>" target="_blank" title="<?php echo $name; ?>"><img src="<?php echo $image; ?>" /></a></div>
        <?php endwhile;
    
    else :
        // no rows found
    endif;
    }
    }
    ?>
    </div>

    Please mark this thread closed. Thank you.

  • Hi @lowercase
    Quick question for you. How did you manage to get your orignal code to work with out referencing the post ID the only way I can get mine to display a single post is to included the post id
    Im using ACF & CPT UI plugins
    Cheers for the advice in advance 🙂

    <?php 
    
    $location = get_field('location_now',22);
    
    if( !empty($location) ):
    ?>
    <div class="acf-map">
        <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
    </div>
    <?php endif; ?>
    

    My aim is to create a stand alone map that loops all the map points but I cant seem to get the template file to work

  • Think that I asked the wrong question, or didn’t put all info (!duh).

    I have two CPTs: Products & tools. In Products you can select related tools using the relationship field.

    The tools have a radio button (wheel_section). On the product page I want to get all relationships and display them in groups based on the value of wheel_section.

    Been searching, racking my brain, biting my nails, etc. but cannot work out how to do this. This is how far I have got – if anyone can point me in the right direction would be very grateful.

    1) Get related posts
    <?php $posts = get_field('product_tools'); if( $posts ): ?>

    2) Look through posts / setup data

    <?php $i=0; foreach( $posts as $post): ?>
     <?php setup_postdata($post); ?>

    3) Get choices from wheel_section radio button
    <?php echo implode(', ', get_field_object('wheel_section')[choices]); ?>

    4) Loop through choices
    This is where I get lost. Now I have an array and I need to loop through each choice and get corresponding label and calculators so I get:

    WHEEL SECTION LABEL 1
    – calculators in wheel section 1

    WHEEL SECTION LABEL 2
    – calculators in wheel section 2

  • Hello and thank you for your answer,
    I tried this but I think I did wrong the code,
    Can you see when you have time?
    thank you

    <?php
    $group_ID = 30109;
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    
    $exclude = array('field_5919f45752917', 'field_5919f46252918', 'field_5919f46a52919');
    
    if( $fields )
    {
    echo '<div class="col-sm-6">';
    echo '<h3>Description:</h3>';
        echo '<ul class="list-unstyled">';
      foreach( $fields as $field_name => $field ) {
      if (in_array($field['key'], $exclude) {
      {
        $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>';
      }
        continue;
      }
    }
      echo '</ul>';
    echo '</div>';
    }
    ?>
  • I would suggest that rather than having this setting on every post that you instead create an options page that has a post object field to allow for the selection of the default” post.

    To do this on every post you will need to create an acf/load_field filter https://www.advancedcustomfields.com/resources/acfload_field/ and do a query in this filter to see if there is another post that already has the value set and if so then disable the field.

  • 
    $name = get_sub_field('name');
    if (get_sub_field('link')) {
      ?>
        <a href="<?php the_sub_field('link'); ?>"><?php echo $name; ?></a>
      <?php 
    } else {
      echo $name;
    }
    
  • The main problem here is that there is no way at all, using WP_Query to match up the values represented by the % pattern in your field names. So for example, it will match if the combination of awards_given_1_year, awards_given_2_program and awards_given_3_level meet the requirements.

    The number of queries you’d need to do with WP_Query would be uncountable.

    It might be possible to remove the % and add enough meta_query conditions to do the work, but this would in all likelihood, time out the page.

    This cannot even be done with a single query using $wpdb, because there is no single MySQL query that can be constructed to do the work. I have looked into this, and have asked the question in various places, including here https://dba.stackexchange.com/questions/118271/matching-same-unknown-characters-in-two-columns, knowing that I would probably never get an answer to the question, but not wanting to give up on the idea.

    Anyway, I just wanted to give you a little background on the difficulty of doing this type of querying.

    This is how I solve the question. 1st thing is that I never use repeaters for anything that I may want to search on if I can help it at all. I will spend days looking at alternate solutions. I’m pretty sure that this is too late for your current project because I’m pretty sure that this question reminds me of previous questions here related to the same type of setup of fields.

    2nd, if I must use a repeater and cannot find another solution, or for some reason it’s too late to change it, then what I do is I create an acf/save_post filter that gets the values from the repeater and puts them into a form that is searchable by much simpler methods.

    
    // priority 20 is after ACF is done
    add_action('acf/save_post', 'convert_repeater_to_wp', 20);
    
    function convert_repeater_to_wp($post_id) {
      if (get_post_type($post_id) != 'profile') {
        // not the right post type
        return;
      }
      // create a meta key to store the new values under
      $meta_key = 'combined_awards_given_repeater'
      // clear all of the existing values for the field before adding new values
      // to make sure it's update correctly
      delete_post_meta($post_id, $meta_key);
      // now we add the values of the repeater to this field
      if (have_rows('awards_given')) {
        while(have_rows('awards_given')) {
          $value = get_sub_field('year').' '.
                     get_sub_field('program').' '.
                     get_sub_field('level');
          add_post_meta($post_id, $meta_key, $value, false);
          // the last value "false" tells WP that this meta key can have multiple values
        } // end while have rows
      } // end if have rows
    } // end function
    

    with the above function in place you can now alter your query to

    
    $args = array(
      'posts_per_page'  => -1,
      'post_type'    => 'profiles',
      'meta_query'  => array(
        array(
          'key'    => 'combined_awards_given_repeater',
          'compare'  => '=',
          'value'    => '2017 Media Relations GRAND PRIZE',
        )
      )
    );
    

    the only hurdle you have is getting the existing values into this field. You can either manually open and update every post if the number is limited… or you can build a cron to do the work by getting every post of the post type, looping through them all and doing the same thing that the function does for every post.

  • I ended up getting this figured out.The fix that worked was having two if statements rather than an if/else statement. I used a simple variable to help with getting the template i needed.

    <?php
    $banners = get_field('new_banner');
    $uri = $_SERVER['REQUEST_URI'];
    $host = $_SERVER['SERVER_NAME'];
    ?>
    
    <?php 
    
    $match = 0;
    
      foreach($banners as $banner){
      	$banner_match = $banner['full_value'];
    
     	if($uri === $banner_match){
    
    		get_template_part('templates/frontpage', 'masthead-alt');
    			$match = 1;
     		}
     	}
     	if($match !== 1) {
    
    		get_template_part('templates/frontpage', 'masthead');
       		}
        
     ?>
  • "type": "image_crop", is not a built in ACF field type and is an add on. Have you tried without this field type plugin active? Do you have any other ACF addons installed? I cannot recreate your problem using only built in ACF field types.

  • Yes deactivated = hidden

    here is the json:

    
    [
        {
            "key": "group_58fdac3805d6e",
            "title": "Standard Seite",
            "fields": [
                {
                    "key": "field_58fdacd119084",
                    "label": "Inhalt",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_58fdad1266b76",
                    "label": "Überschrift",
                    "name": "headline",
                    "type": "textarea",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "50",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "maxlength": "",
                    "rows": 2,
                    "new_lines": "br"
                },
                {
                    "key": "field_58fdad59a6080",
                    "label": "Teasertext",
                    "name": "teasertext",
                    "type": "textarea",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "placeholder": "",
                    "maxlength": 200,
                    "rows": 4,
                    "new_lines": "br"
                },
                {
                    "key": "field_58fdac6456f92",
                    "label": "Teaser Bild",
                    "name": "teaser_image",
                    "type": "image_crop",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "crop_type": "hard",
                    "target_size": "custom",
                    "width": 800,
                    "height": 566,
                    "preview_size": "medium",
                    "force_crop": "yes",
                    "save_in_media_library": "yes",
                    "save_format": "object",
                    "library": "all",
                    "retina_mode": "no"
                },
                {
                    "key": "field_5900981454641",
                    "label": "Text Layout",
                    "name": "copy_layout",
                    "type": "radio",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "choices": {
                        "center": "zentriert",
                        "left": "linksbündig"
                    },
                    "allow_null": 0,
                    "other_choice": 0,
                    "save_other_choice": 0,
                    "default_value": "",
                    "layout": "horizontal",
                    "return_format": "value"
                },
                {
                    "key": "field_58fdac6e56f93",
                    "label": "Text",
                    "name": "copy",
                    "type": "wysiwyg",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "default_value": "",
                    "tabs": "all",
                    "toolbar": "full",
                    "media_upload": 0,
                    "delay": 0
                },
                {
                    "key": "field_58fdacb74ea04",
                    "label": "Flexible Inhalte",
                    "name": "flexible_content_page_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "field_58e26f566db37"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_5900a215b7182",
                    "label": "Links & Verwandte Inhalte",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_5900a1d1cca47",
                    "label": "Links",
                    "name": "related_links_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "group_58f9cbb37d94d"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_593a7f9f6a653",
                    "label": "",
                    "name": "",
                    "type": "message",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "100",
                        "class": "acf-separator",
                        "id": ""
                    },
                    "message": "",
                    "new_lines": "wpautop",
                    "esc_html": 0
                },
                {
                    "key": "field_5900a45388b68",
                    "label": "Verwandte Inhalte",
                    "name": "relationships_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "group_58f9f302af202"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                },
                {
                    "key": "field_593a7fbf586d1",
                    "label": "",
                    "name": "",
                    "type": "message",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "100",
                        "class": "acf-separator",
                        "id": ""
                    },
                    "message": "",
                    "new_lines": "wpautop",
                    "esc_html": 0
                },
                {
                    "key": "field_58fdacbb4ea05",
                    "label": "Slider",
                    "name": "",
                    "type": "tab",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "placement": "top",
                    "endpoint": 0
                },
                {
                    "key": "field_58fdacbd4ea06",
                    "label": "Slider",
                    "name": "slider_clone",
                    "type": "clone",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "clone": [
                        "field_58f87ffd86644",
                        "field_58f8825ba35f4",
                        "field_58f8bb5b31957",
                        "field_58f8bc9b31958"
                    ],
                    "display": "seamless",
                    "layout": "block",
                    "prefix_label": 0,
                    "prefix_name": 0
                }
            ],
            "location": [
                [
                    {
                        "param": "page_template",
                        "operator": "==",
                        "value": "page.php"
                    }
                ]
            ],
            "menu_order": 0,
            "position": "normal",
            "style": "default",
            "label_placement": "top",
            "instruction_placement": "label",
            "hide_on_screen": [
                "excerpt",
                "custom_fields",
                "discussion",
                "comments",
                "categories",
                "tags",
                "send-trackbacks"
            ],
            "active": 1,
            "description": ""
        }
    ]
    
  • Hi John,

    Thanks so much for your help with this; hugely appreciated!

    As it happens, no sooner than I had posted my question on these here boards, I came up with the following solution, and it was very similar to yours, so hopefully it’s a case of great minds thinking alike and all that!

    Thanks again for your reply, and it’s all working brilliantly now!

    Alex

    $meta_query = array(
    				
    				'relation' => 'OR',
    
    				array(
    					'key' => 'end_date',
    					'compare' => '>=',
    					'value' => $today,
    				),
    				
    				array(
                        'key' => 'event_date',
                        'value' => 'standard',
                        'compare' => 'NOT LIKE',
                    ),
    				
    			);
  • It really depends on what else your displaying posts based on when there is no end_date, but you can get all values > today or posts that do not have end_date set something like this

    
    $meta_query = array(
      'relation' => 'OR',
      array(
        'key' => 'end_date',
        'compare' => '>=',
        'value' => $today,
      ),
      array(
        'key' => 'end_date',
        'compare' => 'NOT EXIST'
      ),
    );
    

    https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

  • ACF form can be used to create a new anything, but it requires creating an acf/pre_save_post filter to do the work.

    For example, say that you want to create a new category for post you could create your call acf_form() with array('post_id' => 'new_category') then in the pre_save_post filter

    
    if ($post_id != 'new_catetory') {
      return $post_id;
    }
    // code for creating the new category
    // including setting $post_id to "term_{$new_category_id}"
    

    ACf could be used to do what you want, but it will take quite a bit of coding to accomplish in order to get all the details right. Honestly, I think that your best hope of getting something like this is the BBPress community, or hoping that BBPress adds something like this. What you’re looking for looks like a lot of work, even with ACF to help you with the forms you need.

  • Well ive been looking around with little luck. The forum in question is actually bbpress already. I posted that question in both bbpress and buddypress threads.

    I have a plugin like this that works in phpbb but there doesnt seem to be anything for wordpress yet, if I knew more about writing code id just write it myself.

    While looking around I saw this dev who seemed to be working on something like it using ACF, but it doesnt seem to be live
    https://www.wppluginco.com/product/acf-front-end-form-plugin/

    Associate a Form with BBPress Forums – So you can create a Support Request form that Users are required to complete before submitting a Post in any categories you specify

    Ive been hunting around the page here and saw this page
    https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/

    I just dont know how I would make it post into bbpress instead of making a new wordpress page

  • @jakeodb thank you very much for your solution. I applied it to my project and it is working as intended. I guess I was on the right track when I began exploring the acf/fields/post_object/query filter, but I didn’t keep pressing on. Thanks again!

  • Hi, it’s ok now but i have a new problem :

    i need to check if the “current_value” is equal to “test-selecteur” and add selected to the equal value.

    I think i need have a loop in Jquery to compare and add selected to the correct value.

    Thank you for help

  • Thanks. I think I know what you mean. I played around for a few hours yesterday and I think I’m close, but not quite.

    This is what I have so far – I pass in the post to be copied to the new site and the target blog ID. It should work the same to copy the post on the same site if you were to remove the switch_to_blog() lines.

    public function copy_post_to_blog($post, $target_blog_id) {
                var_dump('copy_post_to_blog');
                $source_blog_id = 1;
    
                switch_to_blog($source_blog_id); // Enforce that we're still on blog ID 1
                $meta = get_post_meta($post->ID);
                $post_custom = get_post_custom($post->ID);
    
                $save_post = $post;
    
                $post->ID = ''; // empty id field, to tell wordpress that this will be a new post
                switch_to_blog($target_blog_id); // switch to target blog
                $inserted_post_id = wp_insert_post($post); // insert the post
    
                $attached_images = array();
    
                foreach($meta as $key => $value) {
    
                    $attach_id = NULL;
    
                    if( strpos($key, 'sections_') === 0 ) {
    
                        switch_to_blog($source_blog_id);
    
                        $new_file_url = $main_site_url . '/wp-content/uploads/' . $post_media_attachment['file'];
    
                        $post_media_attachment = wp_get_attachment_metadata($value[0]);
           
                        switch_to_blog($target_blog_id);
    
                        $main_site_url = get_site_url( get_current_blog_id() );
                        $current_site_url = get_site_url( get_current_blog_id() );
    
                        $img_url = $main_site_url . '/wp-content/uploads/' . $post_media_attachment['file'];
    
                        $info       = pathinfo($img_url);
                        $file_name  = basename($img_url,'.' . $info['extension']);
    
                         // Get the upload directory for the current site
                        $upload_dir = wp_upload_dir();
                        // Make the path to the desired path to the new file we are about to create
                        if( wp_mkdir_p( $upload_dir['path'] ) ) {
    
                            $file = $upload_dir['path'] . '/' . $file_name .'.'. $info['extension'];
    
                        } else {
    
                            $file = $upload_dir['basedir'] . '/' . $file_name .'.'. $info['extension'];
    
                        }
                        
    
                         $image_data = file_get_contents( $main_site_url . '/wp-content/uploads/' . $post_media_attachment['file'] );
    
                        // Add the file contents to the new path with the new filename
                        file_put_contents( $file, $image_data );
    
                        $attachment = array(
                            'post_mime_type' => 'image/jpeg',
                            'post_title'     => sanitize_file_name( $file_name ),
                            'post_content'   => '',
                            'post_status'    => 'inherit',
                            'post_excerpt'   => '',
                            'post_name'      => sanitize_file_name( $file_name ),
                            'guid'           => $file
                        );
    
                        // Attach the new file and its information to the database
                        $attach_id = wp_insert_attachment( $attachment, $file, $inserted_post_id );
    
                        // Include code to process functions below:
                        require_once(ABSPATH . 'wp-admin/includes/image.php');
    
                        // Define attachment metadata
                        $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    
                        wp_update_attachment_metadata( $attach_id, $attach_data );
    
                    }
    
                    $new_value = ( isset($attach_id) ) ? $attach_id : $value[0];
    
                    update_post_meta($inserted_post_id, $key, $new_value);
                }

    I feel like I’m switching blogs too much, maybe that’s an issue…and the $new_value field, what I’m trying to do is if it’s one of my “sections_” ACF fields, save the image value where applicable or just the value itself to the new post.

    What I don’t like about it, besides it not working, is it’s not dynamic – what if there are other ACF fields later…if they aren’t starting with the name “sections_” it won’t get picked up. I don’t really know enough of what’s going on to make this better.

    Do you happen to have any working code or can you help with what I’ve got started?

  • I had a similar requirement to yours and found this when searching for a solution.

    I have managed to get this working using the acf/fields/post_object/query filter.

    The way it brings in the information is a bit harder to debug as it’s all AJAX, but using WP_DEBUG_LOG and error_log to see what data was parsing through helped me come to the solution:

    function cxx_event_balance_individual_option( $args, $field, $post_id ) {
    	
    	// $post_id comes in here as term_# so we need to remove 'term_' to get the term ID
    	$prefix = 'term_';
    	
    	// Also if you are creating a new taxonomy, post_id = 'term_0' so then there's no point in adding a filter
    	if ( 'term_0' != $post_id && substr( $post_id, 0, strlen( $prefix )) == $prefix ) {
    		// Set $term_id to the ID part of $post_id
    		$term_id = substr( $post_id, strlen( $prefix ) );
    		
    		// And adjust the query to filter by specific taxonomy term
    		$args['tax_query'] = array(
    			array(
    				'taxonomy'  => 'product_event',
    				'field'     => 'term_id',
    				'terms'     => $term_id,
    			),
    		);
    	}
    	return $args;
    }

    Hope this helps you out.

  • You can do this using the acf/fields/relationship/query filter https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

  • You can start by taking a look at some of my examples for dynamically setting fields using jQuery and AJAX here https://github.com/Hube2/contact-form-7-dynamic-select-extension. I don’t have an example that does specifically what you’re looking to do, unless you want to use something like select fields for both fields. The basics will be the same, the differences are all due to different things being needed for each type of field.

Viewing 25 results - 11,076 through 11,100 (of 21,318 total)