[Resolved] How to show own excerpt ?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support How to show own excerpt ?

Tagged: ,

This topic contains 20 replies, has 2 voices, and was last updated by  Tom 2 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #104

    Jamal
    Participant

    Hi again,

    I would like to show own excerpt from a meta-box added using the code below

    function generate_addbox() {
    add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'volunteer_opp', 'normal', 'core');
    }
    add_action( 'admin_menu', 'generate_addbox' );

    how would i go about it? Is there a better way to go about this? Thanks

    #105

    Tom
    Keymaster

    Hi Jamal,

    First, you would set the content setting to “None”.

    Then, you could do something like this:

    add_action( 'wpsp_before_content','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
    {
        global $wpsp_id;
        $meta = get_post_meta( $wpsp_id, '_your_custom_meta_key', true );
        if ( isset( $meta ) && '' !== $meta )
            echo $meta;
    }

    Let me know if that works or not 🙂

    #108

    Jamal
    Participant

    Doesn’t seem to work Tom take a look please http://fit.cannysolutions.se/hitta-uppdrag/

    #109

    Tom
    Keymaster

    Time to debug a little 🙂

    Try this:

    add_action( 'wpsp_before_content','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
    {
        global $wpsp_id;
        print_r( $wpsp_id );
        $meta = get_post_meta( $wpsp_id, '_your_custom_meta_key', true );
        if ( isset( $meta ) && '' !== $meta )
            echo $meta;
    }

    Does a number appear?

    #110

    Jamal
    Participant

    It displays 91 next to read more button 🙂

    #111

    Tom
    Keymaster

    Awesome, so the ID is working.

    I’m assuming you updated _your_custom_meta_key with the key you’ve registered/saved in your custom metabox?

    #112

    Tom
    Keymaster

    Scrap that, I was checking the actual post list for the meta instead of the post itself.

    Try this instead:

    add_action( 'wpsp_before_content','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
    {
        $meta = get_post_meta( get_the_ID(), '_your_custom_meta_key', true );
        if ( isset( $meta ) && '' !== $meta )
            echo $meta;
    }
    #113

    Jamal
    Participant

    No luck. I think its best i give you some more info: when i added the code at https://wpshowposts.com/support/topic/how-to-show-own-excerpt/#post-104 i didnt do anything else apart from adding that code. Another function i tried before for the custom meta did require another function to save the contents of that meta-box together with the post. Might that be the problem?

    #114

    Tom
    Keymaster

    Ah, most likely – if you’re adding a custom metabox, you need to add a function so that custom metabox saves the content to the database.

    Have you tried just using the “Excerpt” metabox built into WP? You might have to show it using the “Screen Options” section while editing your post.

    Then if you set the WPSP content type setting to “Excerpt”, it should take the custom excerpt.

    #124

    Jamal
    Participant

    Unfortunately i’m using a plugin that doesn’t support the WP excerpt metabox but do generate an excerpt in the posts. I tried adding something like the example shown here but i was getting two “read more* that i couldn’t get rid of. I did a fresh install (its the only way i know to solve WP issues) and will give it another try tomorrow.

    My little brain is totally fried now, will update tomorrow how far i have come. Thanks !

    #142

    Tom
    Keymaster

    I noticed you were getting a read more tag at one point. I need to do some testing and make sure that those aren’t ever added as we have our own read more button.

    #234

    Jamal
    Participant

    I think im ready to give this another try, help me please.
    I have the code below to include excerpt metabox, im assuming the excerpt will be saved automatically?

    //Enables the Excerpt meta box in volunteer Mgmt edit screen.
    function wpcodex_add_excerpt_support_for_volunteer_opp() {
    	add_post_type_support( 'volunteer_opp', 'excerpt' );
    }
    add_action( 'init', 'wpcodex_add_excerpt_support_volunteer_opp' );
    #239

    Tom
    Keymaster

    I’ve never done that, but it looks like it should.

    When you add an excerpt and save – is your excerpt still there?

    #268

    Jamal
    Participant

    Yes the excerpt is still there when i save but i have now decided against creating own excerpt for i have found a way to hide “Find out more” text that plugin was generating. Sorry to have wasted your time and thanks for all the help, it will be useful in another project for sure.

    #269

    Tom
    Keymaster

    Awesome, glad you found a solution.

    The newest version also doesn’t show the read more text if the more tag is being used 🙂

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.