• Resolved ul71m0

    (@ul71m0)


    Im trying to show page on homepage if checkbox is ticked.

    Im using this plugin for metaboxes.

    So my pages have check box metabox “Show on homepage”. Metabox id is _cmb_check_box and I have treid with few ways but no luck.

    This is my query:

    <?php
                    $args = array(
                        'posts_per_page' => 6,
                        'order' => 'ASC',
                        'post_type'=>'page'
                    );
                    $list_of_posts = new WP_Query($args);
    
                    while ($list_of_posts->have_posts()) : $list_of_posts->the_post(); ?>
                        <div class="box in" id="post-<?php the_ID(); ?>">
                            <?php
                            global $post;
                            $image = get_post_meta($post->ID, '_cmb_promo_image2', true);
                            echo '<img src="' . $image . '">';
                            echo '<div class="box-in">';
                            ?>
                            <h2 class="subtitle"><?php the_title(); ?></h2>
                            <?php
                            global $post;
                            $copy = get_post_meta($post->ID, '_cmb_copy_wysiwyg', true);
                            $copy = substr($copy, 0, 130); $copy .= "...";
                            echo '<p>' . $copy . '</p>'
                            ?>
                            <a href="<?php the_permalink() ?>">FIND OUT MORE ?</a>
                        </div>
                    </div>
                        <?php endwhile;
                    wp_reset_query(); ?>

    So i just need if statement in this query…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ul71m0

    (@ul71m0)

    Ok i got the solution if someone needs it:

    <?php
                $args = array(
                    'posts_per_page' => 6,
                    'order' => 'ASC',
                    'post_type'=>'page',
                    'meta_query' => array(
                        array(
                            'key' => '_cmb_check',
                            'value' => 'on'
                        )
                    )
                );
                $list_of_posts = new WP_Query($args);
    
                while ($list_of_posts->have_posts()) : $list_of_posts->the_post(); ?>
                    <div class="box in" id="post-<?php the_ID(); ?>">
                        <?php
                        global $post;
                        $image = get_post_meta($post->ID, '_cmb_promo_image2', true);
                        echo '<img src="' . $image . '">';
                        echo '<div class="box-in">';
                        ?>
                        <h2 class="subtitle"><?php the_title(); ?></h2>
                        <?php
                        global $post;
                        $copy = get_post_meta($post->ID, '_cmb_copy_wysiwyg', true);
                        $copy = substr($copy, 0, 65); $copy .= "...";
                        echo '<p>' . $copy . '</p>'
                        ?>
                        <a href="<?php the_permalink() ?>">FIND OUT MORE ?</a>
                    </div>
                    </div>
                        <?php endwhile;
                wp_reset_query(); ?>

    Hi ul71m0,

    I am using the same plugin and i am trying to show specific information based on which checkboxes are selected.

    Here is my code
    [Large chunk of mangled code moderated. Please post code or markup between backticks or use the code button. Or better still – use a pastebin.]

    Any insight would be greatly appreciated!
    Thanks!!

    Sorry, here is a link to the page it should be outputting to.

    https://www.williamsselyem.com.php53-21.ord1-1.websitetestlink.com/pinot-noir/4177/

    Scroll down to see “Scores & Reviews”.. That’s where it *should* be.

    I’m not very good at this forum stuff..

    <?php
    			$winenotes = get_post_meta( get_the_ID(), 'Wine-Notes', true );
    			$winereviewscheck = get_post_meta( get_the_ID(), 'reviewmulticheckbox', $single = false );
    
    			$winepoints1 = get_post_meta( get_the_ID(), 'Reviewer-One-Points', true );
    			$winepoints2 = get_post_meta( get_the_ID(), 'Reviewer-Two-Points', true );
    			$winepoints3 = get_post_meta( get_the_ID(), 'Reviewer-Three-Points', true );
    			$winepoints4 = get_post_meta( get_the_ID(), 'Reviewer-Four-Points', true );
    			$winepoints5 = get_post_meta( get_the_ID(), 'Reviewer-Five-Points', true );
    			$winepoints6 = get_post_meta( get_the_ID(), 'Reviewer-Six-Points', true );
    
    			$winereview1blurb = get_post_meta( get_the_ID(), 'Review-One-Blurb', true );
    			$winereview1desc = get_post_meta( get_the_ID(), 'Review-One-Desc', true );
    			$winereview2blurb = get_post_meta( get_the_ID(), 'Review-Two-Blurb', true );
    			$winereview2desc = get_post_meta( get_the_ID(), 'Review-Two-Desc', true );
    			$winereview3blurb = get_post_meta( get_the_ID(), 'Review-Three-Blurb', true );
    			$winereview3desc = get_post_meta( get_the_ID(), 'Review-Three-Desc', true );
    
    			 if($winereviews){
    
    			if ( !empty( $winereviews ) ) { ?>
    			<div class="wine-notes">
            	<h4>Scores and Reviews</h4>
                <div class="scores-reviews">
                <?php if ( $winereviewscheck == 'Reviewer-One' ) //REVIEWER ONE
    			{ ?>
    
                    <div class="points"><span>Points</span><div class="point-number"><?php echo $winepoints1; ?></div></div>
    
                        <?php if ( !empty( $winereview1blurb ) ) { ?>
                            <div class="review">
                                <p><?php echo $winereview1blurb; ?></p>
                            </div>
    					<?php } ?>
    
                        <?php if ( !empty( $winereview1desc ) ) { ?>
                            <div class="review">
                                <p><?php echo $winereview1desc; ?></p>
                            </div>
    
                        <div style="clear:both;"></div>
    					<?php } ?>
    
                <? }else { } ?>
    
                <?php if ( $winereviewscheck == 'Reviewer-Two' ) //REVIEWER TWO
    			 { ?>
    
                    <div class="points"><span>Points</span><div class="point-number"><?php echo $winepoints2; ?></div></div>
    
                        <?php if ( !empty( $winereview2blurb ) ) { ?>
                            <div class="review">
                                <p><?php echo $winereview2blurb; ?></p>
                            </div>
    					<?php } ?>
    
                        <?php if ( !empty( $winereview2desc ) ) { ?>
                            <div class="review">
                                <p><?php echo $winerev2ew1desc; ?></p>
                            </div>
    
                        <div style="clear:both;"></div>
    					<?php } ?>
    
                <? }else { } ?>
    
                </div>
    
            </div><!--/wine-notes-->
    
    <? } } else { } ?>
    </pre>
    <pre>
    		//	Reviewer One
    			//Wine Score
    			array(
    				'name' => 'Reviewer One Points',
    				'desc' => 'Wine score for reviewer one',
    				'id'   => 'Reviewer-One-Points',
    				'type' => 'text_small',),
    			//Reviewer 01 blurb
    			array(
    				'name' => 'Review One Blurb',
    				'desc' => 'Review blurb',
    				'id'   => 'Review-One-Blurb',
    				'type' => 'textarea_small',
    			),
    			//Reviewer 01 long desc
    			array(
    				'name' => 'Review One Long Description',
    				'desc' => 'Review full description',
    				'id'   => 'Review-One-Desc',
    				'type' => 'wysiwyg',
    				'options' => array(	'textarea_rows' => 5, ),
    		),
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query posts if metabox checkbox is checked’ is closed to new replies.