Get all wordpress custom fields from a page or a post

October 10, 2009

Sometimes you may need to get all custom fields from a specific post or page. How can we do that? Just paste the following functions on the functions.php files from your theme. Note: The function have lots of comments so it will help you to understand how it works. function all_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; ... [Read the full story]

get wordpress custom fields outside the loop

June 12, 2009

Custom fields are very useful and are used on many WordPress blogs. But how to easily get custom fields values outside the loop? To display a custom field value outside the loop, simply use the following code. Don’t forget to replace Myfield on line 4 by the name of the custom field you want to display.   <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'MyField', true); ?>  Read More →

Create invisible wordpress custom fields

June 2, 2009

Many plugins use custom fields to store data about individual posts. When a plugin adds a custom fields, its key and value (or name and value) are listed in the Custom Fields meta box. For instance, a syntax hilighting plugin may set a custom field syntax_enabled on posts that use the syntax highlighting CSS. Often the user doesn’t need to see this information and it can leed to needless confusion. Unless the user needs to edit these custm field values there’s really no need to have them listed here. How to Hide... [Read the full story]

Show WordPress Posts With a Specific Custom Field and Value

May 14, 2009

Ever wanted to be able to only get the list of wordpress posts which have a specific custom field key as well as a specific value? Sometimes you only want to show wordpress posts that you’ve added a specific custom field to. For instance, lets say you write wordpress host and wordpress template reviews and for each you give them a custom field “review_type” with the value set to either “url” or “template”. So how would you show posts that are only wordpress template reviews? Simply... [Read the full story]

Display post based on custom fields with a custom query

February 20, 2009

Many blogger interested to know how to be able to display posts based on custom fields values. The first thing to do is to create a page template. The code below will display your posts, based on the following condition: Post must have a custom field with key tag and value email. Of course, you can change it in the query to make the code fits your needs. <?php /* Template Name: Custom query */ $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id ... [Read the full story]