Support

Account

Forum Replies Created

  • Ah yeah, that makes sense, I did not think of it from a meta_key/value pair within WP.

    Should really think about my responses before sending them ha.

    Thanks, John as always, such a genius!

  • Hey John,

    Solved my issues, noticed that update_field() does not work unless it exists. Of course, the field does not exist until something is done with it.

    I used the standard update_meta() instead which works fine.

  • It was exactly that…

    I am guessing duplicated names mean in the backend, ACF does not know which one to update so causing issues?

    Would it be something for the future for ACF to flag duplicated names?

  • Hi John,

    In the end I used a plugin you created which allows you to remove fields based on a users permission level. I just removed all the fields I wanted from the tab to anyone below admin.

  • Can’t remember how I solved this but I did….

  • Hi James,

    If I swap to a stock theme it won’t then have my ACF fields, that that is not really useful.

    I will email support.

    Thanks very much for your reply!

  • Hi John,

    The post is actually created first and then the fields are updated after the post creation is complete.

    The storing of the field value correctly seems to be the problem. Swapping to YYYYMMDD works but for some reason I still need to open the post and re-save for it to the start returning it as DD/MM/YYYY. It is like ACF if doing something else once it laods and resaves the value from YYYYMMDD.

    Is there a way of saving it YYYMMDD but without having to then go into the post and resaving for it to return it in the other value?

  • I have mentioned above but:

    Date format is DD/MM/YYYY
    Field is: update_field()

  • This is good!

    Is there a way though, to show the fields in WP admin for posts that do have content in the old fields?

    That way it can be hidden for new posts but still be editable for old ones.

  • If this would be running on multiple pages what is the best ways of getting the postID dependent on the page it is currently on?

  • I am using JetPack’s Infinite Scroll for the post display with updated args for the display of posts.

    To update the post display on different pages I want to be able to control the category of the posts that are displayed. Here is the code:

    function mm_infinite_scroll_query_args($args) {
       if ( get_field('page_cat') ) {
        $page_cat = get_field('page_cat');
            $new_args = array(
                'posts_per_page'   => $args['posts_per_page'],
                'paged'   => $args['paged'],
                'orderby'          => 'date',
                'order'            => 'DESC',
                'cat'    => $page_cat,
                'post_type'        => array( 'post', 'features', 'it_hardware', 'videos' ),
                'post_status'      => 'publish',
            );
            return $new_args;
         else {
    
            $new_args = array(
                'posts_per_page'   => $args['posts_per_page'],
                'paged'   => $args['paged'],
                'orderby'          => 'date',
                'cat'    => 5,
                'order'            => 'DESC',
                'post_type'        => array( 'post', 'features', 'it_hardware', 'videos' ),
                'post_status'      => 'publish',
            );
            return $new_args;
        }
    
    }

    Because infinite scroll runs off the page the code is all in the functions.php file hence why I want to access a field on the page which links to the loop arguments.

  • Thanks for that, I look for this documentation but could not find it!

  • Thanks for this, it will help me get in the right direction!

  • Hi John

    Yeah that is the similar functionality I am looking for.

    At the moment <!– Next Page –> only works for the first content section and not any of ACF’s.

    That is why I would like to add a repeater type which you can insert where you want in the repeater loop to break up into another page.

  • I have managed to work it out here is the answer if anyone needs it. This would go in your function.php file

    // retrieves the attachment ID from the file URL
    function get_image_id($image_url) {
        global $wpdb;
        $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
        return $attachment[0];
    }
    
    //Set the featured image on save of the post
    add_action('save_post', 'set_featured_image_from_image');
    
    //set featured image as main image.
    function set_featured_image_from_image()
    {
            $has_thumbnail = get_the_post_thumbnail($post->ID);
            
            //If there is not featured image get the other image.
            if (!$has_thumbnail) {
            //get the url of the ACF image and get the ID of that image
                $image_url = get_field('main_image');
                $image_id = get_image_id($image_url);
    
                if ($image_id) {
                    set_post_thumbnail($post->ID, $image_id);
                }
            }
        
    }

    I am outputting just the url from the image so I had to reverse get the ID. Those who are using the full object should be able to get the ID more easily.

  • I had my repeater running through another file, to get it to work I had to run it through the repeater again on the page I wanted the repeater to run in the file. Like this.

        <?php if( have_rows('layout_section') ) { } else { } ?>
            <?php wp_reset_query(); ?>
        <?php get_template_part( 'layout-strips' );  ?>

    No idea why this works but it does.

    I would try emailing support as they have been really helpful to me.

  • Yeah tried that and still no luck.

    I just added a text sub field called ‘text’ and entered some text in the field.

    Used your code and nothing has shown up on the page.

    <?php
    if( have_rows('layout_section') ):
        while ( have_rows('layout_section') ) : the_row();
            the_sub_field('text');
        endwhile;
    else :
    endif;
    ?>

    For some reason ACF is just not seeing any fields in the repeater field.

  • Tried that way and still no luck. It is still saying there are no rows found when there are rows.

    <?php if( have_rows('layout_section') ): ?>
    
        <?php while ( have_rows('layout_section') ) : ?>
    
            <?php the_row(); ?>
    
            <?php if (get_sub_field('layout_section_type') == "feat_section") { ?>
    
                <p>Featured Section</p>
    
            <?php } elseif ( get_sub_field('layout_section_type') == "feat2" ) { ?>
    
                <p>Featured Section 2</p>
    
            <?php } elseif ( get_sub_field('layout_section_type') == "feat3" ) { ?>
    
                <p>Featured Section 3</p>
    
            <?php } else { ?>
    
                <p>Normal Section</p>
    
            <?php } ?>
    
        <?php endwhile; ?>
    
    <?php
    else :
        echo '<p>No Rows Found</p>';
        // no rows found
    endif;
    ?>

    Here are the config pages. First one of the repeater field itself

    The layout type options

    Just using it for text at the moment for debugging

Viewing 18 posts - 1 through 18 (of 18 total)