Support

Account

Forum Replies Created

  • echo apply_filters( 'the_content', get_post_field('post_content', $id ) );

    Replace $id with the ID of the post with the blocks you want to include. I’ve created a “header” and “footer” custom post types which I use solely for storing specific blocks I designed for said parts (which basically allows me to grab the desired “header” and “footer” posts/blocks from wherever I want).

  • I encountered the very same issue. After a few hours, I decided to try to use the second function mentioned on https://www.advancedcustomfields.com/resources/google-map/ (the one which is not suggested for ACFPRO useres):

    function my_acf_google_map_api( $api ){
    	
    	$api['key'] = 'xxx';
    	
    	return $api;
    	
    }
    add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

    … and it works. I have no idea if (with future updates) this may result in issues on the long run, but nevertheless, it’s a solution for now.

  • Try with the following code (make sure to either remove or rename the above/previous featured image function). Just replace your gallery field with get_field(‘thisisyourgalleryfield’, $post_id ) and see if it works.

    
    add_action('acf/save_post', 'flex_FeaturedImageSetByACF', 50);
    
    function flex_FeaturedImageSetByACF() {
    
        $current_screen         = get_current_screen(); // Current admin screen needed to identify the current cpt
        $current_cpt_name       = $current_screen->post_type; // Current cpt name
        $current_cpt_support    = 'thumbnail'; // We want to check if the CPT supports this feature
    
        global $post;
    
        $post_id                = ( $post->ID ); // Current post ID
        $post_gallery_field     = get_field('thisisyourgalleryfield', $post_id ); // ACF field
    
        if  ( !empty( $post_id ) ) {
    
            if ( isset( $post_gallery_field['0'] ) ) {
    
                $post_image_id          = $post_gallery_field['0']['id']; // ACF image filed ID
                $post_image_url         = $post_gallery_field['0']['url']; // ACF image filed URL
    
                // If current cpt supports thumbnails/featured images
    
                if ( post_type_supports( $current_cpt_name, $current_cpt_support ) ) {
    
                    if ( ( $post_image_url ) AND ( ( $post_image_url ) != ( get_the_post_thumbnail() ) ) ) {
    
                        update_post_meta($post_id, '_thumbnail_id', $post_image_id);
    
                    }
    
                }
    
            } else {
    
                update_post_meta( $post_id, '_thumbnail_id', 0 );
    
            }
    
        }
    
    }
  • I ended up using a sligtily modified version. You have to place this code in your functions.php and have to save each individual post in order to show/update your featured image (unfortunately, if you already have many posts this may prove to be a tedious task). Make sure you run these functions only for the custom post types you need.

    
    
    add_action('acf/save_post', 'flex_CustomExcerptSetByACF', 50);
    
    function flex_CustomExcerptSetByACF() {
    
        global $post;
    
        $post_id        = ( $post->ID ); // Current post ID
        $post_excerpt   = get_field( 'post_excerpt', $post_id ); // ACF field
    
        if ( ( !empty( $post_id ) ) AND ( $post_excerpt ) ) {
    
            $post_array     = array(
    
                'ID'            => $post_id,
                'post_excerpt'	=> $post_excerpt
    
            );
    
            remove_action('save_post', 'flex_CustomExcerptSetByACF', 50); // Unhook this function so it doesn't loop infinitely
    
            wp_update_post( $post_array );
    
            add_action( 'save_post', 'flex_CustomExcerptSetByACF', 50); // Re-hook this function
    
        }
    
    }
    
    add_action('acf/save_post', 'flex_FeaturedImageSetByACF', 50);
    
    function flex_FeaturedImageSetByACF() {
    
        $current_screen         = get_current_screen(); // Current admin screen needed to identify the current cpt
        $current_cpt_name       = $current_screen->post_type; // Current cpt name
        $current_cpt_support    = 'thumbnail'; // We want to check if the CPT supports this feature
    
        global $post;
    
        $post_id                = ( $post->ID ); // Current post ID
        $post_image_field       = get_field('post_head_img', $post_id ); // ACF field
    
        if  ( !empty( $post_id ) ) {
    
            if ( !empty( $post_image_field ) ) {
    
                $post_image_id          = $post_image_field['id']; // ACF image filed ID
                $post_image_url         = $post_image_field['url']; // ACF image filed URL
    
                // If current cpt supports thumbnails/featured images
    
                if ( post_type_supports( $current_cpt_name, $current_cpt_support ) ) {
    
                    if ( ( $post_image_url ) AND ( ( $post_image_url ) != ( get_the_post_thumbnail() ) ) ) {
    
                        update_post_meta($post_id, '_thumbnail_id', $post_image_id);
    
                    }
    
                }
    
            } else {
    
                update_post_meta( $post_id, '_thumbnail_id', 0 );
    
            }
    
        }
    
    }
    
    

    On a side note, if your issue is limited to showing exceprt & featured images on certain template files, it may prove easier to edit these.

  • Hi, I have a question if you can spare a few moments: a couple of years ago I created a page builder using flexible and repeater fields – while I kept things very simple (around 5-6 layouts with a couple of fields each), I had no issues. Alas, once I started adding complexity (doubled the layouts, each with 15-20ish fields) saving a post started taking 10-20 seconds (or even more), while the overall browser performance rendered the interface barely usable (very low framerate/browser begging me to kill it).

    Given this issue, I went for a different approach:

    • For post & pages I used a “lite” page builder with very few fields.
    • For the front-page (which usually has more content and diversity), i created a custom post type called “blocks” and loaded field-groups depending on the taxonomy (e.g. “block-gallery”, “block-map”, etc).

    Now, what I wanted to ask you is: while I’m pretty sure ACF performance has improved since 2 years ago, I can’t help but wonder – do you think there’s a chance you may end up hitting a wall where too many layouts & fields may hinder/ruin the users experience (specifically on mobile devices or old computers)? Do you have a different approach in mind?

  • Using wp_check_post_lock() would allow me to gain a lot of flexibily, I really like to sound of it – unfortunately I may be failing at understanding how to properly use it: I get a “Uncaught Error: Call to undefined function wp_check_post_lock()” both on the front/backend. Could you point me in the right direction perhaps (I understand this is more of a WordPress request at this point, but if you have a few minutes to spare I would appreciate it a lot!).

    Meanwhile I’m gonna open up a ticket as you suggested.
    Thanks in advance!

  • Thanks, you’ve been incredibly helpful! Granted my code (which I pasted below) may or may not make you and others cringe in horror, I managed to make it work somehow (I’ve put together a function that handles featured images and custom excerpt one).

    Now, I did a lot of testing and I found that both functions work correctly with the hook “save_post” instead of “acf/save_post“. I’m not sure why, as I’m not sure why if I switch to “acf/save_post“, only the featured image function keeps working (while the excerpt one, “reads” the previous saved value, hence requiring me to save twice). If I then try to lower the priority I receive some internal server errors. But I guess I’m more puzzled at this point as wheter what I accomplished is indeed correct or it’s faulty (and this is the reason it does not work with “acf/save_post”).

    In any way, thanks again for pointing me in the right direction!

    
    add_action('save_post', 'flex_CustomExcerptSetByACF', 50);
    function flex_CustomExcerptSetByACF() {
    
        global $post;
    
        $post_id        = ( $post->ID ); // Current post ID
        $post_excerpt   = get_field( 'post_excerpt', $post_id ); // ACF field
    
        if ( ( $post_id ) AND ( $post_excerpt ) ) {
    
            $post_array     = array(
    
                'ID'            => $post_id,
                'post_excerpt'	=> $post_excerpt
    
            );
    
            remove_action('save_post', 'flex_CustomExcerptSetByACF', 50); // Unhook this function so it doesn't loop infinitely
    
            wp_update_post( $post_array );
    
            add_action( 'save_post', 'flex_CustomExcerptSetByACF', 50); // Re-hook this function
    
        }
    
    }
    
    add_action('save_post', 'flex_FeaturedImageSetByACF', 50);
    
    function flex_FeaturedImageSetByACF() {
    
        $current_screen         = get_current_screen(); // Current admin screen needed to identify the current cpt
        $current_cpt_name       = $current_screen->post_type; // Current cpt name
        $current_cpt_support    = 'thumbnail'; // We want to check if the CPT supports this feature
    
        global $post;
    
        $post_id                = ( $post->ID ); // Current post ID
        $post_image_field       = get_field('post_head_img', $post_id ); // ACF field
    
        if ( ( $post_id ) AND ( $post_image_field ) ) {
    
            $post_image_id          = $post_image_field['id']; // ACF image filed ID
            $post_image_url         = $post_image_field['url']; // ACF image filed URL
    
            // If current cpt supports thumbnails/featured images
    
            if ( post_type_supports( $current_cpt_name, $current_cpt_support ) ) {
    
                if ( ( $post_image_url ) AND ( ( $post_image_url ) != ( get_the_post_thumbnail() ) ) ) {
    
                    update_post_meta($post_id, '_thumbnail_id', $post_image_id);
    
                }
    
            }
    
        }
    
    }
    
  • Thank you, removing line breaks indeed solved my problem.

    Yet I had to take one more step inbetween due to the previous (failed) import attempts. I tried to do as it follows:

    1) Delete the corrupted/failed import on the target WP installation
    2) Edit the original message field on the source WP installation in order to delete line-breaks
    3) Save
    4) Export as XML
    5) Import back

    But it didn’t work: even if I was actually importing a “line-break” free message field, either no fields were created on the target WP installation (as result of the new import procedure), or only one message field would show up… with line breaks.

    So I cloned the original fieldgroup (on the source WP installation) with Duplicate Post (http://wordpress.org/plugins/duplicate-post/), exported it, imported it back and… it worked.

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