• I have gotten the custom fields where you enter in a value to work, but I cannot get the custom fields with a checkbox to work. Currently I have an option where you can either check or uncheck a box if you want the words “Free Shipping” to display on the page, but I am using the following code, and it always says free shipping:
    <?php if ( get_post_meta($post->ID, ‘shipping’, true) ) { ?>
    <p class=”freeship”>Includes Free Shipping!</p>
    <?php } else { ?>
    <?php } ?>

    See, I’m trying to use an if, then statement to make the free shipping display if the checkbox is checked and not to display anything at all if the checkbox is not checked.

Viewing 6 replies - 1 through 6 (of 6 total)
  • yea, im having a similar problem with custom field checkbox…

    anyone have any words of advice?

    Well first check your Database to see if the values are actually saving.

    I have added checkboxes too and i save my post but nothing is saved.

    jayo

    (@jayo)

    @ krugazul.

    I mean, how do you actually call it into a page to bring up the posts that are checked when you write a post.

    I think there is a bug that means checkboxes in plugin options don’t save without a workaround/custom saving method

    <?php if ( get_post_meta($post->ID, 'shipping', true) ) { ?>
    <p class="freeship">Includes Free Shipping!</p>
    <?php } else { ?>
    <?php } ?>

    so to get this example working just do this

    <?php $shipping = get_post_meta($post->ID, "shipping", $single = true);
    	if($shipping !== 'false') {
    	echo '<p class="freeship">Includes Free Shipping!</p>';
    	} ?>

    so there is a way for custom field that is a text field

    <?php $custom_field = get_post_meta($post->ID, "custom_field", $single = true);
    	if($custom_field !== '') {
    	echo '<li> <span>' . $custom_field; echo '</span>Head:</li> ';
    	} ?>

    So the first example will echo your html content only if chebox is selected.
    Second example will echo html content only if field have some text in it. I’m using it here and works perfect,

    cheers

    Hello
    I was glad I found this post but I ran into a bit of trouble when trying to have multiple conditional items on a page.

    So far I have my checkboxes working in the admin to hide and show the content when needed. But I want to have a second or more optional field display if chosen in the admin. It seems I’m doing something wrong with the query_posts() tag. If I use it only once I get both boxes showing up correctly conditionally.

    Here’s the code I’m using if anyone can help I would gladly appreciated :-]
    URL: https://moisesl.com/blog/about

    <div class="lowerBox">
    
    <?php if (get_post_meta($post->ID, 'news_awards', true) and query_posts('category_name=news-awards&amp;showposts=4'))  { ?>
    	<!-- Begin Awards -->
    	<div id="news_and_awards">
    	<ul>
        <?php while (have_posts()) : the_post(); ?>
            <li><?php the_title(); ?> <a href="<?php the_permalink(); ?>"><b>more>></b></a></li>
        <?php endwhile;?>
        <li><a href="#">TEst News and Awards</a></li>
        </ul>
        </div>
        <!-- End Awards -->
    
    <?php } else { ?>
    News and awards displaying nothing because its false
    <?php } ?>
    
    <?php if (get_post_meta($post->ID, 'offices', true) and query_posts('category_name=office-locations&amp;showposts=5')) { ?>
        <!-- Begin Offices -->
        <div id="office_locations">
        <ul>
        <?php while (have_posts()) : the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile;?>
        </ul>
            <ul>
              <li><a href="#">TEst Office</a></li>
              <li><a href="#"></a></li>
            </ul>
        </div>
        <!-- End Offices -->
    
    <?php } else { ?>
    <?php } ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Field Checkbox with WordPress [Flutter]’ is closed to new replies.