Support

Account

Forum Replies Created

  • Hi @remseo

    I apologize for the delayed response.

    I tried what you recommended but did not work. However, I did figure out a way to make it work. I had to first surround everything in the have_rows() and the_row() of the group field.

    This is what worked for me:

    $group = get_field('group_field');
    $heading = $group['heading'];
    $text = $group['text'];
    // repeater field is called 'links_list'
    // repeater sub field called 'link'
    if( have_rows('group_field') ) : while( have_rows('group_field') : the_row();
    ?>
        <h3><?php echo $heading; ?></h3>
        <?php echo $text; ?>
        <?php if( have_rows('links_list') ) : ?>
        <ul class="links-list">
            <?php while( have_rows('lists_list') ) : the_row(); $link = get_sub_field('link'); ?>
            <li><a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>"><?php echo $link['title']; ?></a></li>
            <?php endwhile; ?>
        </ul>
        <?php endif; ?>
    <?php endwhile; endif; ?>
  • I just noticed I have a typo in my code. The while loop has have_rows('lists_list') where is should have said have_rows('links_list'). Even though I mistyped it here, it was correct in my code. I didn’t copy and past my code because of formatting/indentation reasons. So that is NOT the reason my repeater wasn’t working. I also tried another group with a repeater and did the same thing. Just seems like the have_rows() does not work correctly when inside a group field.

  • @gavin310 I’m not sure about how to override the functionality of the size requirements specifically for svgs in ACF. When I ran into this issue my svg image file had a small width/height, even though it’s scalable. It was easy to tell because putting the svg on a page without any height width attributes it still rendered small rather than filling the existing container. The only advice I have is to edit the size of the svg before uploading. Unfortunately I don’t know exactly how to do that. I had to have our graphic designer do it for me.

  • @franzkekko How does your question relate to ACF? This forum is specifically for questions about ACF. Your question looks like it would be better suited for Stack Overflow.

  • @trishah I think you will need to better explain how you want to add the counter variable to a shortcode. Can you share your loop code, or perhaps even an example of how you want the shortcode to look after the counter variable has been added? Is the variable being added as a parameter? I’m trying to figure out what your goal is and why you would want to add a counter variable to a shortcode in the first place.

    The only reason I could see you wanting to add the counter variable value to a shortcode is if you were appending the value to a class property or something. If that is the case you could do something like.

    $counter = 1;
    if( have_rows('repeater_field') ) : while( have_rows('repeater_field') ) : the_row();
        $contactUs = get_sub_field('contact_form_shorcode');
        $newClass = 'class="instance-' . $counter . '"';
        $short = str_replace( 'class=""', $newClass, $contactUs);
        echo do_shortcode($short);
        $counter++;
    endwhile; endif;

    If you can provide more info, especially what you want the output to be, I may be able to provide more specific help.

  • This post was marked as spam, so I had recreated the same topic at https://support.advancedcustomfields.com/forums/topic/query-posts-by-checkbox-value-dynamically/ where it was solved.

  • I probably made some error earlier and didn’t realize it. Anyways, talking with you helped me worked through it. I appreciate it regardless.

  • I don’t know what is going on. I checked the change I made per your advice and it is retrieving the correct posts. It’s grabbing all the ones that have at least one of the same checkbox values while omitting those that didn’t.

    But I just tried reverting back to use just $subject rather than '"'.$subject.'"' and now it’s working as it should. Besides adding post__not_id to exclude the current post, everything is the same as it was when it wasn’t working for me. Strange.

  • @hube2 You da man! That worked! I don’t understand why but I’m not going lose any sleep over it. Thank you very much!!!

  • Hi @hube2 the values are text strings. Here are my choices copied direction from the field group editor:

    agile : Agile
    bom : Basics of Modeling
    gsn : GSN
    mm : Mind Mapping
    safe : SafeML
    se : Systems Engineering
    uml : UML
    uc : Use Cases

  • Oh I forgot to mention that the return type for subjects is set to value only.

  • @trenbania So if I’m understanding you correctly you are trying to retrieve field values in a block…from a block on a different page? If that is the case then I have no idea how to do that.

    Normally when I use the relationship field its retrieving posts from a specific post type. On CPT’s I don’t use Gutenberg, I just create the acf fields that are assigned to the cpt, not a block. Then the code we were discussing would work. But my CPT’s are very standardized and don’t have the need for arbitrary content via blocks. I have never had to retrieve values in a block from another block on a different page.

    You may be able to use get_post_meta() but since I have never tried that with ACF I’m not sure exactly how that will work, or if it will work at all. Here is a forum topic I found real quick that might help you. https://support.advancedcustomfields.com/forums/topic/want-to-use-get_post_meta-instead-of-get_field-for-array/ You might need to also do a check to see if the block exists using has_block() https://developer.wordpress.org/reference/functions/has_block/

    Sorry couldn’t be more help man.

  • @trenbania Just to make sure, are the fields ‘scientific_name’, ‘family’ and ‘scientific_tree_family’ assigned to the post type you’re pulling in via the relationship field? And those fields are not in group field or repeater? You shouldn’t have to but may need to pass the post id when retrieving the field values.

    Maybe try:

    $posts = get_field('info_from_growing');
    if( $posts ) {
    foreach( $posts as $post) { // variable must be called $post (IMPORTANT)
    setup_postdata($post);
    $id = $post->ID;
    $scientificName = get_field('scientific_name', $id);
    $family = get_field('family', $id);
    $scientificTreeFamily = get_field('scientific_tree_family', $id);
    // do something with the values
    ?>
    <div>
        <p>Scientific Name: <?php echo $scientificName; ?></p>
        <p>Family: <?php echo $family; ?></p>
        <p>Tree: <?php echo $scientificTreeFamily; ?></p>
    </div>
    <?php
    }
    }
  • Hmmm, no replies at all. Geez, didn’t think my question was that out there.

    Anyways, if anyone else has the same question here is how ended solving my issue.

    $member_id = get_the_ID();
    $meta_query = array(
        array(
    	'key' => 'podcast_pub_date',
    	'value' => date('Ymd'),
    	'type' => 'DATE',
    	'compare' => '<='				   
        ),
        array(
    	'key' => 'podcast_authors',
    	'value' => $member_id,
    	'compare' => 'LIKE'
        )
    );
    			   
    $podcast_args = array(
        'post_type' => 'podcasts',
        'posts_per_page' => 3,
        'meta_key' => 'podcast_publication_date',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'meta_query' => $meta_query
    );

    I don’t have a ton of test data yet and still are testing this but seems to be working as I need it to.

  • @trenbania the_field() directly prints the value…which is the same thing as doing echo get_field(). If you’re assigning the value to a variable, you must use get_field() Other than that everything looks fine to me.

  • @trenbania you’re using the_field('field_name', $p->ID) when you should be using get_field('field_name', $p->ID).

    Also, if you read the instructions for Relationship filed, you must call the foreach variable $post in order to override the global post variable. So your foreach loop should be: foreach($posts as $post). Then you have to setup the postdata: setup_postdata($post)

  • Found a solution and wanted to post it in case someone was looking for the same thing. I realized I was approaching this wrong. I later found that acf_register_block_type() function accepts a argument called 'enqueue_assets'

    So now my code looks like this, and it works like a charm.

    // register logo carousel block
    	acf_register_block_type(array(
    		'name'	=>	'logo_carousel',
    		'title'	 =>	__('Logo Carousel'),
    		'description'	=>	__('Logo Carousel'),
    		'mode'	=> 'edit',
    		'render_template'	=>	'blocks/content/logo-carousel.php',
    		'enqueue_assets'	=> function(){
    			wp_enqueue_style( 'slick-slider-css', 'https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css', array(), null, 'all');
    			wp_enqueue_script('slick-slider-js', 'https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js', array( 'jquery' ), null, true );
    			wp_enqueue_script('slick-slider-init', get_template_directory_uri() . '/blocks/scripts/logo-carousel.js', array(), null, true );
    		},
    		'category'	=> 'my-custom-blocks',
    		'icon'	=>	'images-alt2',
    		'keywords'	=>	array( 'logo', 'carousel', 'slider'),
    	));

    I feel kind of dumb for not figuring it out earlier, especially since I had already been using 'enqueue_script'. Learning experience I guess.

  • @adam_g is show_information a group field and media is a gallery field inside the group? That’s the only reason I can think of why you would have $images = $show['media'];

    Have you inspected the element or view source of the page to see if all the images are being added in the page’s rendered HTML?

  • I found my issue, I had a typo in the category argument. I fixed and my custom block now shows up!

  • @dabeecher Were you ever able to resolve the issue with custom blocks not showing up in Gutenberg with ACF 5.8.0-beta3? I just downloaded beta 3 today and none of my custom blocks are appearing as options in Gutenburg.

  • I apologize in advance if I’m not understanding your question correctly.

    So you have a custom post type (produktark) with a checkbox field in it. Then on another page, you have a ACF to select which checkbox value from the CPT you want to query by?

    Assuming that vis_produktark_fra is the field key for the field on the page you want to display the custom posts on, then you should be able to use get_field() rather than the_field(). the_field echos the value, which you don’t want to do.

    So assuming I’m understanding you correctly, your code could look like:

    
    <?php 
    
    $vis_produktark_fra = get_field('vis_produktark_fra');
    // args
    					
    $args = array(
    
    'post_type' => 'produktark',
    'posts_per_page' => -1,
    'meta_query' => array(
               array(
                   'key'       => 'produkttyp',
                   'compare'   => 'LIKE',
                    'value'     =>  $vis_produktark_fra
                    )
    )
    );
    					 
    // get results
    $the_query = new WP_Query( $args );
    					 
    // The Loop
    ?>
    

    OR

    
    <?php 
    
    // args
    					
    $args = array(
    
    'post_type' => 'produktark',
    'posts_per_page' => -1,
    'meta_query' => array(
               array(
                   'key'       => 'produkttyp',
                   'compare'   => 'LIKE',
                    'value'     =>  get_field('vis_produktark_fra')
                    )
    )
    );
    					 
    // get results
    $the_query = new WP_Query( $args );
    					 
    // The Loop
    ?>
    

    this is basically the same thing in my first code snipped

  • The links you shared doesn’t look like they were entered correctly. The all return a 404, but as you can see, part of the link is a hyperlink, the the rest of it is in plain text afterwards. So we can’t see what you’re trying to show us.

    When you say you disabled Gutenberg, did you do this by enabling the Classic Editor?

    After you created your field groups, did you edit your template files to retrieve and then display the values…either using get_field() or the_field()? Sorry, had to ask, just saw a forum where a guy thought the values would magically display in the front-end without doing any coding the page/post’s template file.

  • @nycplugged As @lynx_gd mentioned, you have to retrieve and then display the value in your post’s template file. ACF is a developer’s plugin, not a user’s plugin. So if you aren’t familiar with PHP or feel comfortable editing template files, then ACF is not what you will want to use.

  • Thanks for the quick replies! I’m going to have to take some time and play around with it using both your suggestions. I’ve always found @hube2 advice to be awesome, so I’ll give it go. I’ll report back and let you know how it works out. Thanks again for all of your help, I really appreciate it.

  • Hi @mhowellsmead , thank you for your reply. I had considered going the cpt route, the image I shared was just one simple example. My client is going to want to create many charts, each type of chart comparing different products and features. So as of now, even my client can’t provide me with a complete list of possible features a product can have. More products with different features are going to be made available and my client is not going to want me to have to go in and add new features as they become available.

    So sadly, creating the features as choices in a field group is not going to viable option. And I’m having a tough time thinking of a way to let the client enter custom features that will be simple and intuitive for them to use for all the different products and features they will comparing.

    I was wondering if there is a way to create 2 sets of repeaters. The first repeater for the features. The second repeater would be for products. Then inside the products repeater I would have a nested repeater where they could enter a value for a given feature, like a check, text or leave blank. The part I’m wondering if there is a way to dynamically create as many rows in the nested repeater as there are in the features repeater, and then maybe display the value of each row of the features repeater in each row of the nested repeater.

    So for example, if I created 5 features (in the first repeater): feature 1, feature 2, feature 3, feature 4 and feature 5. Then when I create a new row in the products repeater, there will be a nested repeater for whether this product has this feature. So in this nested repeater, there would already be 5 rows created, and value entered for its corresponding row in the features repeater displays as a label or something.

    I hope I didn’t confuse anyone further. Just trying to think of a creative solution. I’m just not sure how to pull it off.

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

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.