Dump All Custom Fields

WordPress has a built in function, the_meta(), for outputting all custom fields. But this function is limited in that it doesn't always output all of them. For example, it misses custom fields added by plugins which begin with an _ underscore.

This bit of code uses an alternate function, get_post_custom() which will return all of them, and display all values. Good for debugging.

<h3>All Post Meta</h3>

<?php $getPostCustom=get_post_custom(); // Get all the data ?>

    foreach($getPostCustom as $name=>$value) {

        echo "<strong>".$name."</strong>"."  =>  ";

        foreach($value as $nameAr=>$valueAr) {
                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo $nameAr."  =>  ";
                echo var_dump($valueAr);

        echo "<br /><br />";



  1. User Avatar
    Jonathan Bird
    Permalink to comment#

    Ah just what I’ve been looking for. Easy to customize into what you want like a list pulling out all image URLs.

  2. User Avatar
    Permalink to comment#

    Nice one – thanks!

  3. User Avatar
    Permalink to comment#

    Excellent, helps a lot!

  4. User Avatar
    Permalink to comment#

    Looks like I get to be 2016’s comment. Thanks for this, came in handy today!

  5. User Avatar

    I’m finding this very handy in 2017, too!

    Nice work!

  6. User Avatar
    Permalink to comment#

    Still useful in 2018. Thanks

  7. User Avatar
    Permalink to comment#

    I just gotta say, the yearly comments are hilarious.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.