The Best Way to Get All WordPress Custom Fields


Sponsored Links






WordPress Custom Fields is the most usable field ever, we can give many information using custom fields, we can added custom image post, added some content and many many things we can do.

Display WordPress Custom Fields

Display WordPress Custom Fields

Sometime we need to Get all wordpress custom fields from a page or a post and display it in our post content or page or whatever in our WordPress. Write down this code below in your functions.php theme

Get All Custom Fields Code

<?php
function display_my_customs($id = 0){
//if we want to run this function on a page of our choosing them the next section is skipped.
//if not it grabs the ID of the current page and uses it from now on.
if ($id == 0) :
global $wp_query;
$content_array = $wp_query-&gt;get_queried_object();
$id = $content_array-&gt;ID;
endif;

//knocks the first 3 elements off the array as they are WP entries and i dont want them.
$first_array = array_slice(get_post_custom_keys($id), 3);

//first loop puts everything into an array, but its badly composed
foreach ($first_array as $key =&gt; $value) :
$second_array[$value] = get_post_meta($id, $value, FALSE);

//so the second loop puts the data into a associative array
foreach($second_array as $second_key =&gt; $second_value) :
$result[$second_key] = $second_value[0];
endforeach;
endforeach;

//and returns the array.
return $result;
}
?>
 

This code will get all your custom field and display it, to display or using Get All Custom Fields in WordPress code use this simple steps

<?php $result = display_my_customs();
echo $result['my_meta_key'];?>

this code original created by LiveXP

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

Create Custom Page with Custom Loop and Query

Created WordPress as CMS? I am guarantee you’ll need this tricks. Because WordPress Custom Page is Gregorius tools we can use to create custom design/layout and whatever we want. I will show you how to Create Custom Page with Custom … Read More

How To Display Custom Content to Search Engine Visitors

There are so many WordPress blog, some of them added unique features, right now I will show you how to display custom content to Search Engine visitors only, You can replace what do you want to be added on Search … Read More

Added Custom Size on Your Post Thumbnails

Chadcoleman created wonderful tutorials, how to added Custom Size Post Thumbnail. All we need to do only put some functions and use it whatever and whenever you want. Added this code on your functions.php That it's, you have new custom

How To Exclude Pages or Posts from Search Results Page

For some reason, sometimes we need to exclude some contents on our WordPress site from search results in our WordPress. Example we didn't need to display our about page to be indexed or searchable by WordPress search. To enable this … Read More

Modify Custom excerpt length

On WordPress 2.9 there are new featured that we can added on the_excerpt(), one of them is change the excerpt length. How to modify Custom excerpt length is really simple. We only needed to put some function on our functions.php … Read More

Tutorial To Display a Different Number of Post on Search Result

Did you know that, WordPress search result have the same number of post with original WordPress loop, you can check your setting on Settings » Reading » Blog pages show at most. But for some reason, we need to show … Read More

The Best Way to Get All WordPress Custom Fields / WordPress Tricks

Sometime we need to Get all wordpress custom fields from a page or a post and display it in our post content or page or whatever in our WordPress. read more

Source: http://wptricks.net/the-best-way-to-get-all-wordpress-custom-fields/

WordPress Custom Fields 101: Tips, Tricks, and Hacks

pointed out that we have a lot of hacks and tutorials that cover WordPress Custom fields mriulian The best way of doing this would be to use the built-in Post read more

Source: http://www.wpbeginner.com/wp-tutorials/wordpress-custom-fields-101-tips-tricks-and-hacks/

Learn how to use Wordpress Custom Fields | Kriesi.at - Wordpress

Learn how to use WordPress Custom Fields, to the data in a superior way we use the function. get Custom Fields Hacks For WordPress « Best Design Content read more

Source: http://www.kriesi.at/archives/how-to-use-wordpress-custom-fields

Extend WordPress With Custom Fields - Smashing WordPress

here are inspiring, and this is quite possibly the best way to create a unique post design for WordPress. Set a different background for each post with custom fields read more

Source: http://wp.smashingmagazine.com/2010/04/29/extend-wordpress-with-custom-fields/

Showing thumbnails with WordPress custom fields

How to use WordPress custom fields to show thumbnail images on Is there a way to get several thumbs in one post? 65 Of The Best WordPress Tutorials « Junkiee.Net read more

Source: http://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts


5 Responses to The Best Way to Get All WordPress Custom Fields

  1. Pingback: Tweets that mention How To Get all WordPress custom fields from a page or a post # WordPress Tricks & Tips -- Topsy.com

  2. Lawrie says:

    …or, you could just do this:

  3. … makes heavy use of WordPress’ custom fields … sort of understood custom fields I now get … Using WordPress Custom Fields (in 2 parts) » Critical Flare; 65 Of The Best WordPress

  4. David says:

    I agree.
    is a lot simpler. It does display all< of the meta data/custom fields though. However, that’s what I personally needed. Using “More Fields” or other plugins, you can always make hidden fields to not show them, and use the same technique.

    That can be put within the single.php/post.php above content() or inside: content(meta());
    To get the custom fields into the Excerpt, it can be put into formatting.php

    Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>