• Resolved s1dekick223

    (@s1dekick223)


    Hey,

    i’m new to cmb2 and i hope you can help me.

    I want to echo my posts but only when i triggered a checkbox in backend.

    this is my current code im a little bit lost.

    <?php get_header(); ?>
    
    <?php
    
    $taxonomies = get_object_taxonomies( array( 'post_type' => 'faq',) );
     
    foreach( $taxonomies as $taxonomy ) :
     
        // Gets every "category" (term) in this taxonomy to get the respective posts
        $terms = get_terms( array( 'taxonomy' => 'faqt', 'parent' => 0, 'hide_empty' => 0, ) );
     
        foreach( $terms as $term ) : ?>
    <div>
        <h3><a href='faqt/<? echo $term->slug; ?>'><? echo $term->name; ?></a></h3>
            </div>
     
            <?php
            $args = array(
                    'post_type' => 'faq',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                        array(
                            'taxonomy' => $taxonomy,
                            'field' => 'slug',
                            'terms' => $term->slug,
                        )
                    )
     
                );
            $posts = new WP_Query($args);
     
            if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>
     
    
        <ul>
            <li><a href="<?php echo get_permalink(); ?>"><?php  echo get_the_title(); ?></a></li>
       </ul>
    
     
                            <?php the_excerpt(); ?>
           
     
            <?php endwhile; endif; ?>
    
        <a href='faqt/<? echo $term->slug; ?>' class=“btn btn-secondary”>Alle Fragen</a>
    
    </div>
    <hr/>
       
     
        <?php endforeach;
    
     
    endforeach; ?>
    
    <?php get_footer(); ?>
    

    I hope you guys can help me

    thx ! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter s1dekick223

    (@s1dekick223)

    fixed by myself, was really stupid

    <?php
    // Grab the metadata from the database
    $text = get_post_meta( get_the_ID(), 'faqt_topquestion', true );
    
    if ($text) { ?>   
    
        <ul>
            <li><a href="<?php echo get_permalink(); ?>"><?php  echo get_the_title(); ?></a></li>
       </ul>
    <?php
    
    		   }
    ?>
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You got this!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CMB2 Checkbox to enable/disable post output’ is closed to new replies.