Home › Forums › Pro Support › Help me achieve something similar
- This topic has 8 replies, 2 voices, and was last updated 6 years, 7 months ago by
Tom.
-
AuthorPosts
-
October 18, 2016 at 4:43 am #892
Jamal
ParticipantHi Tom,
Would you kindly help me please achieve something similar to how this plugin displays the events? I would like to show CPT created by event organiser plugin to list upcoming activities and hide that activity as soon its finished. How would i go about it?
Sorry if im too vague right now, but i can provide some more info and examples. Thanks !
October 18, 2016 at 8:00 am #893October 18, 2016 at 9:32 am #894Tom
KeymasterHi Jamal,
For the look of it, it looks like you’d need to add some custom meta and insert it using the hooks we’ve discussed in this forum. Let me know if you need more info on that.
As for removing the post once the event is done, this plugin looks promising: https://wordpress.org/plugins/post-expirator/
October 20, 2016 at 1:04 pm #906Jamal
ParticipantSorry didn’t get time to try this earlier. Tom, how can i display all post meta or multiple meta keys using code below? Thanks
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; }
October 20, 2016 at 1:49 pm #908Tom
KeymasterExactly like that – you’d just add more variables:
add_action( 'wpsp_before_content','wpsp_add_custom_meta' ); function wpsp_add_custom_meta() { $first_meta = get_post_meta( get_the_ID(), '_your_custom_meta_key', true ); $second_meta = get_post_meta( get_the_ID(), '_your_second_custom_meta_key', true ); $third_meta = get_post_meta( get_the_ID(), '_your_second_custom_meta_key', true ); if ( isset( $first_meta ) && '' !== $first_meta ) echo $first_meta; if ( isset( $second_meta ) && '' !== $second_meta ) echo $second_meta; if ( isset( $third_meta ) && '' !== $third_meta ) echo $third_meta; }
October 21, 2016 at 1:00 pm #912Jamal
ParticipantI hate to bother you with this again but im so close yet far enough not to make it work on myself.
I have changed plugins and is now using events manager. I would like to get the post meta and not a custom post meta i added myself so was wondering if using code below can work
function get_post_meta( $post_id, $key = '', $single = false ) { return get_metadata('post', $post_id, $key, $single); }
When i do this (below) i get all the meta keys as seen here http://pastebin.com/fGjdvhwD
//Wpsp show meta instead of content add_action( 'wpsp_before_content','wpsp_add_custom_meta' ); function wpsp_add_custom_meta() { $meta = get_post_meta( get_the_ID(), '', false ); if ( isset( $meta ) && '' !== $meta ) print_r( $meta ); }
Now when i use the code in your last reply, i get all the relevant meta but all of it on one line.
To summarize my question:
1. Can i use get_metadata to output all the post metadata?
2. If no. 1 is not possible, how can i put a line break after each meta data?Please do tell me if this is out of the scope of this forum, i would hate to bother you unnecessarily
October 22, 2016 at 12:39 am #915Tom
KeymasterHi Jamal,
No worries!
I don’t think you can get all post metadata – at least not looking pretty.
To get line breaks, you just need to add HTML to the PHP.
For example:
if ( isset( $first_meta ) && '' !== $first_meta ) echo $first_meta;
Becomes:
if ( isset( $first_meta ) && '' !== $first_meta ) { ?> <p> <?php echo $first_meta; ?> <p> <?php }
Hope this helps 🙂
October 22, 2016 at 2:41 pm #917Jamal
ParticipantI’m enlightened, thank you very much Tom for your patience and tremendous help 🙂
October 22, 2016 at 4:04 pm #918Tom
KeymasterYou’re very welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.