How to Display Custom Fields Outside The Loop in WordPress

Interactive Online > Blog  > CMS  > WordPress  > How to Display Custom Fields Outside The Loop in WordPress

How to Display Custom Fields Outside The Loop in WordPress

In this article we will show you how you can display custom fields outside the loop. This tutorial will allow you to expand the possibilities of what you can do with WordPress.

How to Display Custom Fields Outside The Loop in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Add a Digg Button in your WordPress using Custom Fields
  2. Embed Custom CSS in Your Single Posts with Custom Fields
  3. How to Display Any Number of Posts in a WordPress Loop


There will be times that you need to display post-specific content for example a different sidebar for a specific post. Usually post specific contents are added via a custom field which can only be displayed inside a post loop. In this article we will show you how you can display custom fields outside the loop. This tutorial will allow you to expand the possibilities of what you can do with WordPress.

The code will look like this:

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>

You will need to make sure that you change the part where it says “Your-Custom-Field”.

This code is just the basic code. You can play around with it and use all the query_post arguments to fit your needs. You can even display another post’s custom fields on a single page of a different post.

In this (Example) at Uzzz, we are displaying the custom fields of a specific portfolio post, into the single post of a related testimonial post.

This snippet is very useful for theme developers. If you have any questions, feel free to ask in the comment or via email.

How to Display Custom Fields Outside The Loop in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Add a Digg Button in your WordPress using Custom Fields
  2. Embed Custom CSS in Your Single Posts with Custom Fields
  3. How to Display Any Number of Posts in a WordPress Loop

(read full article on source site)
Free Website for Your Dental Practice
See why our dental practice websites exceed the features & value of your typcial dentist website.
  • No cookie-cutter websites
  • No duplicate content
  • Custom built with a unique look and feel
  • Unique content written by professional writers
  • Set yourself apart from other dentists
  • The key to your online success!
* we never share your e-mail with third parties.