We're merging with GenerateBlocks! Learn more here.

[Resolved] Help me achieve something similar

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Help me achieve something similar

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #892
    Jamal
    Participant

    Hi 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 !

    #893
    Jamal
    Participant
    #894
    Tom
    Keymaster

    Hi 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/

    #906
    Jamal
    Participant

    Sorry 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;
    }
    #908
    Tom
    Keymaster

    Exactly 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;
    }
    #912
    Jamal
    Participant

    I 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

    #915
    Tom
    Keymaster

    Hi 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 🙂

    #917
    Jamal
    Participant

    I’m enlightened, thank you very much Tom for your patience and tremendous help 🙂

    #918
    Tom
    Keymaster

    You’re very welcome 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.