• Resolved McAsh

    (@mcash)


    Hi guys

    I am working with the free ‘Boldy’ theme from Site5 (https://wordpress.site5.net/boldy/) which has a predefined excerpt from the_content.

    However, I have build a post template that uses the plugin ‘Advanced Custom Fields’ (https://www.advancedcustomfields.com/) and on this template the editor fill in content in the different fields and thereby not in the_content. This means that there’s no excerpt shown for these posts and therefore I want to pull an excerpt from one of the custom fields. I can display an entire Advanced Custom Field by using <?php echo the_field(‘field_name’); ?> but how can I limit the output of this command to only 20-30 words?

    Any help would be greatly appreciated ?? Thanks..

Viewing 15 replies - 16 through 30 (of 31 total)
  • Thanks keeslemeljer. Allthough that didn’t seem to do the work. But you have a good point with the possibility of breaking the html.

    Do you, or anyone else have a good suggestion on how to make a advanced cusomt field equivalent to the_content but with word limit and a read more tag without using the devider in the editor? Do you know what I mean?

    In thought, that would make an excerpt but with the “the_content” tag instead. That wouldn’t break my html would it?

    To pull data from my advanced custom field wysivyg editor I use <?php the_field('innehall'); ?>. How can I put an automatic word limit to that tag and also display a reda more tag if it exceeds the word limit?

    Thanks again!
    Jeppe

    https://jeppeblomgren.se

    Moderator keesiemeijer

    (@keesiemeijer)

    Why not use a manual excerpt if it’s equivalent to the_content but with word limit? Manual excerpts can have html tags.

    https://codex.www.ads-software.com/Excerpt#Excerpt.2C_automatic_excerpt.2C_and_teaser

    Aha, so manual excerpt shows tags? Didn’t know that. I’ll try it.

    Thanks again
    /Jeppe

    Hi again. That still doesnt do it for me the way i need this. You see, my client can’t or isn’t supposed to know how to write tags. If I make manual excerpts she will have to write the tags herself. That is going to end up in my lap anyway. S? what I need is an automatic excerpt (she writes really long posts) for the first page. But at the same time I want especially links to work in the excerpt since some post are very short, and doesnt excced the word limit, hence does not not get a read more link. If the link isn’t visible and you cant klick to go se the post where link is clickable – its useless.

    I guess I’m trying to make the site idiot proof. Any more suggestions?

    Cheers / Jeppe

    Moderator keesiemeijer

    (@keesiemeijer)

    Hi all – great post!
    Hope you won’t mind me jumping in with slightly different question, but same plugin and topic (excerpts)

    I am using ACF and need to be able to display search results excerpts – I’ve tried with Search Everything plugin – which does provide search results (at least something) for the custom field. So now I have search result but it only displays the post title – no excerpt text at all https://www.ads-software.com/extend/plugins/search-everything/

    I need to display an excerpt as per normal search. But I think this issue is to do with ACF not Search Everything.

    I am unable to manually create excerpts for the custom fields because the user (member) have control over the post contents and update it regualarly.

    Anybody got a suggestions please – I need to fix this so I can sleep!
    Thank you in advance.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @iamhere, rather than trying to change the topic on a resolved thread, please start your own instead.

    You’ll get better support that way.

    https://www.ads-software.com/support/plugin/search-everything#postform

    @jan

    Thank you for your opinion, though I feel this is not a different topic.
    “pull excerpt from Advanced Custom Field” is exactly what I need in the search results.

    Also, the very audience I am trying to communicate with (experience with ACF and excerpts) are in this topic and will probably find it useful to know the answer, since this issue is common to all ACF users.

    Nonetheless, I will admit I hadn’t noticed it was marked resolved (and in which case, why is it not closed?)

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Thank you for your opinion,

    You’re welcome. ??

    though I feel this is not a different topic.

    It is a different topic.

    You do want us other volunteers to focus on your problem, right? Starting your own thread in that plugin’s forum will get you better support for that plugin. This thread isn’t about that plugin.

    (and in which case, why is it not closed?)

    Resolved topics aren’t automatically closed as far as I know. That way the OP can come back and say “Whoops, my mistake! Post #12345 didn’t really solve it for me. Any other ideas now that I’ve tried that?”

    You get the idea.

    @keesiemeijer thanks for this – it would be great if there was a way to define the field_name in the actual template file, so if there is more than one field that needs shortened we don’t need loads of instances of the snippet in functions.php.

    an alternate to $text = get_field('field_name');
    so I could use something like <?php echo custom_field_excerpt('field_name'); ?>

    is that possible?! ??

    function custom_field_excerpt($title) {
    			global $post;
    			$text = get_field($title);
    			if ( '' != $text ) {
    				$text = strip_shortcodes( $text );
    				$text = apply_filters('the_content', $text);
    				$text = str_replace(']]>', ']]>', $text);
    				$excerpt_length = 20; // 20 words
    				$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    				$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    			}
    			return apply_filters('the_excerpt', $text);
    		}

    then use <?php echo custom_field_excerpt('field_name'); ?>

    Beauty post. Thanks keesiemeijer!

    Thanks keesiemeijer for the code snippet on displaying custom field excerpts. You rock. perfect solution to my little problem.

    The expert code Venkmanuk posted works as a charm for most of my pages. But in the occasions I want to us on a page where it is depending on its post id id doesnt work. For the ACF code it is easy to fix: <?php the_field('acfname', $value->ID); ?>
    So I add the =>ID of the page and it load the value that is in the afc field.
    For the custom_field_expert it doesn’t work:
    <?php echo custom_field_excerpt('afcname', $value->ID); ?>
    It still shows no text.

    any ideas?

    Hi, nice function! Is there a way to define the amount of words of the excerpt length for different instances of the template tag?

    Thanks in advance.

    ps: sorry for my english.

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘How to pull excerpt from Advanced Custom Field’ is closed to new replies.