Home › Forums › Pro Support › How to show own excerpt ?
Tagged: hook, own-excerpt
- This topic has 20 replies, 2 voices, and was last updated 6 years, 10 months ago by
Tom.
-
AuthorPosts
-
July 24, 2016 at 12:06 pm #104
Jamal
ParticipantHi 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
July 24, 2016 at 12:09 pm #105Tom
KeymasterHi 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 🙂
July 24, 2016 at 12:27 pm #108Jamal
ParticipantDoesn’t seem to work Tom take a look please http://fit.cannysolutions.se/hitta-uppdrag/
July 24, 2016 at 12:31 pm #109Tom
KeymasterTime 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?
July 24, 2016 at 12:34 pm #110Jamal
ParticipantIt displays 91 next to read more button 🙂
July 24, 2016 at 12:48 pm #111Tom
KeymasterAwesome, 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?July 24, 2016 at 12:56 pm #112Tom
KeymasterScrap 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; }
July 24, 2016 at 1:03 pm #113Jamal
ParticipantNo 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?
July 24, 2016 at 1:09 pm #114Tom
KeymasterAh, 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.
July 24, 2016 at 3:12 pm #124Jamal
ParticipantUnfortunately 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 !
July 24, 2016 at 6:28 pm #142Tom
KeymasterI 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.
July 25, 2016 at 2:59 pm #234Jamal
ParticipantI 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' );
July 25, 2016 at 3:36 pm #239Tom
KeymasterI’ve never done that, but it looks like it should.
When you add an excerpt and save – is your excerpt still there?
July 26, 2016 at 3:48 am #268Jamal
ParticipantYes 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.
July 26, 2016 at 9:07 am #269Tom
KeymasterAwesome, glad you found a solution.
The newest version also doesn’t show the read more text if the more tag is being used 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.