Connect with us

Tips & Tricks

Echo custom fields in any category

Here is a neat trick. Say you want to show a custom field in you post or in a certain categories post. There is a simple code you need to write in order to accomplish this:

<?php $image = get_post_meta($post->ID, "image", $single = true); ?>
<?php if($image != '') : if(in_category(7)) { echo ''; } else { ?>
<img src="<?php echo $image ?>" alt="<?php the_title(); ?>" /></a>

In the example above I am calling the variable $image and telling the server that it equals the value of “image” inside get_post_meta or “custom field” of the current post.

Then we are asking if that variable $image doesn’t equal nothing or != and if it is in the category id of 7, echo what ever is in the single quotes (which is nothing in this example), otherwise show the <img> and the value inside “image” which should be the location of the image.

Update: Thanks to Austin from PressedWords for pointing out his trick, from the comment below.

3 Comments

3 Comments

  1. Pingback: WordPress Links - Week 2 2009 | WPStart.org - WordPress themes, plugins and news

You must be logged in to post a comment Login

Random Search Terms

Title

Top Articles

Top Searches

powered by WassUp

Recent Posts: Fully Net Worth . com

Peter Morton Net Worth: How Rich is Harry Morton’s Father?

Peter Morton Net Worth: How Rich is Harry Morton’s Father?

Peter Morton is an American businessman best known as the co-founder of the Hard Rock Café and also a chain of dining restaurants. As of 2019, Peter Morton net worth is estimated to be $800 million. Peter was born on August 7, 1947, in Chicago, Illinois. He is the son of Arnie Morton, founder of […]

AzChike Net Worth: How Rich is the Rapper from Los Angeles?

AzChike Net Worth: How Rich is the Rapper from Los Angeles?

AzChike is an American rapper who is from South Central, Los Angeles. He is best known for his hit songs “Burn Rubber Again” and “Licked Up”. As of 2019, AzChike net worth is estimated to be $250,000. Growing up, he loved to ride bikes and was a social kid who liked to have fun with […]

Azriel Clary Wiki, Parents, Bio: Where is Azriel Clary Now?

Azriel Clary Wiki, Parents, Bio: Where is Azriel Clary Now?

Azriel Clary is an American singer and one of R. Kelly’s alleged sex cult victims. Azriel met R. Kelly at the age of 17 and she convinced her parents to go on tour with him. Her parents allowed her to go on a trip with R. Kelly with a belief that he would mentor in […]