WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode for the_meta() (2 posts)

  1. rrddzzz
    Member
    Posted 1 year ago #

    I have shortcode to display individual keys but need one to display all keys.
    Has anyone crated a shortcode to display all meta keys like the function the_meta() does?

    function the_meta() {
            if ( $keys = get_post_custom_keys() ) {
                    echo "<ul class='post-meta'>\n";
    	                foreach ( (array) $keys as $key ) {
    	                        $keyt = trim($key);
    	                        if ( is_protected_meta( $keyt, 'post' ) )
    	                                continue;
    	                        $values = array_map('trim', get_post_custom_values($key));
    	                        $value = implode($values,', ');
    	                        echo apply_filters('the_meta_key', "
    <li><span class='post-meta-key'>$key:</span> $value</li>
    \n", $key, $value);
    	                }
    	                echo "\n";
    	        }
    	}

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  2. bcworkz
    Member
    Posted 1 year ago #

    Wouldn't be hard to create. Use the same function definition for the shortcode handler function definition, except instead of echo outs, concatenate the same into a string, and then finally, return the string.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.