• I create a customizer to select specific category post but my challenge now is that if i click selected category, the loop is not displaying it rather still display all. What am i missing out in this code

    
    	<?php
    // Get pages set in the customizer (if any)
    $pages = array();
    for ( $count = 1; $count <= 5; $count++ ) {
    	$mod = get_theme_mod( 'showcase-page-' . $count );
    	if ( 'page-none-selected' != $mod ) {
    		$pages[] = $mod;
    	}
    }
    
    $args = array(
    	'posts_per_page' => 5,
    	'post_type' => 'post',
    	'post__in' => $pages,
    	'orderby' => 'post__in'
    );
    
    $q = new WP_Query( $args );
    $leadingcount = 3; 
    	?>
    		
    		<div class="row">
    			<?php while ( $q->have_posts() ) : $q->the_post(); ?>
    				<div class="col-<?php echo $leadingcount; ?>">
    					<h3>
    						<a href="<?php the_permalink(); ?>">
    								<h2><?php the_title(); ?></h2>
    						</a>
    					</h3>
    					<?php the_excerpt(); ?>
    					<?php the_category(); ?>
    				</div>
    			<?php endwhile; ?>
    			<?php wp_reset_postdata(); ?>
    		</div>
    
    	
    <main>
    
    	for ( $count = 1; $count <= 4; $count++ ) {
    
    		// Add color scheme setting and control.
    		$wp_customize->add_setting( 'showcase-page-' . $count, array(
    			'default'           => '',
    			'sanitize_callback' => 'absint'
    		) );
    
    		$wp_customize->add_control( 'showcase-page-' . $count, array(
    			'label'    => __( 'Select Category', 'textdomain' ),
    			'type'     => 'select',
    			'section'  => 'showcase',
    			 'choices' => $option_categories,
    		) );
    		
    
    		
    		
    
    	}
    
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You’re adding settings 1-4 but trying to get 1-5. Getting the non-existent 5th value returns an empty string, which is invalid in a post__in arg, so WP_Query ignores the entire arg.

Viewing 1 replies (of 1 total)
  • The topic ‘What am i missing out in this theme_mod’ is closed to new replies.