Tagged: ,

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #636984

    HI, I am trying to get ‘advanced custom fields (ACF)’ to work with enfold. In particular, the posts shortcodes from the avia editor. In other words, when choosing to show blog posts with the template builder in grid format, I want to pull in extra data from my posts from ACF.

    I have been unsuccesfully editing the childtheme/shortcodes/postslider.php file, I can get some of the data but it seems to just repeat itself rather than getting the individual posts values.

    I have been intouch with plugin support for ACF and they have said:

    It seems that the
    global $post;
    method is not working for your case.

    The problem is the
    get_field()
    function doesn’t know the right post for each excerpt. To fix it, you need to pass the ID of the post. Could you please ask the theme author how to get the ID of the post when you use the “avf_post_slider_entry_excerpt” hook? Is it possible that the ID is passed in the $entry variable?

    …. can anyone help out with this?

    #637169

    Hey dannhanks,

    The easiest way to get the post ID is by opening the post in admin dashboard

    There are several other methods please check https://premium.wpmudev.org/blog/display-wordpress-post-page-ids/

    Best regards,
    Vinay

    #637178

    hi, thanks Vinay but you have misunderstood. Its to do with the loop in:
    childtheme/shortcodes/postslider.php

    I am trying to get ACF’s custom fields to work dynamically in the above file.

    thanks

    #638162

    Hi, to save any further confusion:
    acf eample

    #638444

    Hi,

    Thank you for the info. Something like this should work:

    function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) {
    	$field = get_field('fieldname', $entry->ID);
            // do something to the $field
    	return $excerpt;
    }
    add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4);

    Best regards,
    Ismael

    #639233

    HI,
    I have added this in place in my postslider.php file so my code now looks like this:

     $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
    					$excerpt = apply_filters( 'avf_post_slider_entry_excerpt', $excerpt, $prepare_excerpt, $permalink, $entry );
    					$output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div>" : "";
    					// addition as advised above
    					function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) {
    	$field = get_field('excerpt', $entry->ID);
            // do something to the $field
    	return $excerpt;
    }
    add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4);
    					// end of addition as advised above
                        $output .= "</div>";

    … this broke the site saying error message:

    Fatal error: Cannot redeclare avf_post_slider_entry_excerpt_func() (previously declared in /public_html/wp-content/themes/childtheme/shortcodes/postslider.php:453) in /public_html/wp-content/themes/childtheme/shortcodes/postslider.php on line 453

    Any ideas?
    thanks!

    #639661

    Hi,

    That code should go in the functions.php file, not in the postslider.php file. It’s a filter for the post excerpt. What is the name of the custom field that you’re trying to add?

    Best regards,
    Ismael

    #640807

    hi, there are a few I need to add onto this page but one of them is called excerpt.

    #640813

    Hi,

    You can use this function to get the_excerpt:
    https://codex.wordpress.org/Function_Reference/get_the_excerpt

    Best regards,
    Josue

    #640822

    Hi, I tried adding the text to the functions file and nothing happend, no extra content on the post-slider.
    thanks

    #641198

    Hey!

    Please post the login details here so that we can check the name of the custom fields. And while you’re on it, please check if the following code does anything:

    function avf_post_slider_entry_excerpt_func($excerpt, $prepare_excerpt, $permalink, $entry ) {
    	$field = get_field('excerpt', $entry->ID);
            // do something to the $field
            $excerpt = $field . $excerpt;
    	return $excerpt;
    }
    add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_func', 10, 4);

    Cheers!
    Ismael

    #642009

    Hi Ismael,

    I finally got to the bottom of this, in the postslider.php file, I needed to add the code:

    $output .= get_field('field-name', $entry->ID);
    

    Thanks for your help!

    Dann

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘how to get the ID of the post when you use the “avf_post_slider_entry_excerpt”’ is closed to new replies.