• I’m entering hour number six of this problem and have scoured the Internet searching for help. So I’m turning finally to the WP forum.

    My website is https://www.reevolver.com
    I’ll paste my current code below my quesions.

    1. I’ve got 5 custom fields that I want to show on posts of one specific category (see: https://www.reevolver.com/index.php/quests/loggerhead/02/homemade-butter-without-a-churn/ the 5 fields at the top of the post). I don’t have a problem adding those fields to each post I want them added to, but they’re showing up on all the posts and I can’t figure out how to keep them from appearing on posts I don’t want them on (such as: https://www.reevolver.com/index.php/reevolver/02/quest-hierarchy/).

    2. For the fifth field I’ve got 5 .gifs that I have set, depending on whether I enter 1s, 2s, 3s, 4s, or 5s to display one of the 5 .gifs (It’s supposed to be a basic difficulty rating). And the .gif shows up, but only the 1s. I put in any of the other keys and still only the 1s shows up.

    Hopefully someone can give me a clue. Code follows. Thanks.

    <b><?php $my_custom_field = get_post_meta($post->ID, “Quest Title”, true);
    echo “Quest Title: “.$my_custom_field.””; ?></b>

    <?php $my_custom_field = get_post_meta($post->ID, “Discipline”, true);
    echo “Discipline: “.$my_custom_field.””; ?>
    <?php $my_custom_field = get_post_meta($post->ID, “Quest Level”, true);
    echo “Hierarchal Rank: “.$my_custom_field.””; ?>
    <?php $my_custom_field = get_post_meta($post->ID, “Quest Number”, true);
    echo “Quest Designation: “.$my_custom_field.””; ?>
    <?php $my_custom_field = get_post_meta($post->ID, “Difficulty”, true);
    if($my_custom_field = “1s”) {
    echo “Difficulty: “, ‘<img src=”/wp-content/uploads/2010/02/1S.gif”>’;
    } elseif($my_custom_field = ‘2s’) {
    echo “Difficulty: “, ‘<img src=”/wp-content/uploads/2010/02/2S.gif”>’;
    } elseif($my_custom_field = ‘3s’) {
    echo “Difficulty: “, ‘<img src=”/wp-content/uploads/2010/02/3S.gif”>’;
    } elseif($my_custom_field = ‘4s’) {
    echo “Difficulty: “, ‘<img src=”/wp-content/uploads/2010/02/4S.gif”>’;
    } elseif($my_custom_field = ‘5s’) {
    echo “Difficulty: “, ‘<img src=”/wp-content/uploads/2010/02/5S.gif”>’;
    }; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Give this a try, all you essentially need is a few conditions, and the correct comparison operator…

    <?php
    $quest_title = get_post_meta( $post->ID , "Quest Title" , true );
    $quest_level = get_post_meta( $post->ID , "Quest Level" , true );
    $quest_number = get_post_meta( $post->ID , "Quest Number" , true );
    
    $discipline = get_post_meta( $post->ID , "Discipline" , true );
    $difficulty = get_post_meta( $post->ID , "Difficulty" , true );
    
    if( $quest_title )
    	echo "Quest Title: ".$quest_title;
    if( $discipline )
    	echo "Discipline: ".$discipline;
    if( $quest_level )
    	echo "Hierarchal Rank: ".$quest_level;
    if( $quest_number )
    	echo "Quest Designation: ".$quest_number; 
    
    if( $difficulty ) {
    	echo 'Difficulty: ';
    	switch( $difficulty ) {
    		case '1s':
    			echo '<img src="/wp-content/uploads/2010/02/1S.gif" />';
    		break;
    		case '2s':
    			echo '<img src="/wp-content/uploads/2010/02/2S.gif" />';
    		break;
    		case '3s':
    			echo '<img src="/wp-content/uploads/2010/02/3S.gif" />';
    		break;
    		case '4s':
    			echo '<img src="/wp-content/uploads/2010/02/4S.gif" />';
    		break;
    		case '5s':
    			echo '<img src="/wp-content/uploads/2010/02/5S.gif" />';
    		break;
    		default:
    			echo '';
    		break;
    	}
    }
    ?>

    NOTE: When checking if a value is equal to another, you should use a comparison operator, like ==. A single equals = is for setting, not comparison.

    More on operators: https://php.net/manual/en/language.operators.comparison.php

    Thread Starter mattmitchell8

    (@mattmitchell8)

    PERFECT!!!!!!! Thanks so much that works like a charm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Two Questions on Custom Fields’ is closed to new replies.