Title: ACF true/false loop
Last modified: September 22, 2016

---

# ACF true/false loop

 *  [ivan76](https://wordpress.org/support/users/ivan76/)
 * (@ivan76)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/acf-truefalse-loop/)
 * Hello, I have a problem.
    I’ve created a custom post type Portfolio in my site
   and with ACF I’ve created 4 extra fields : 2 for images (“imagen” e “imagen_destacados”),
   a text field (“description”) and a true/ false field (“selected”). I’ve also 
   added a taxonomy to the custom post type named “category” with five options.
 *     ```
       function create_posttype() {
   
       	register_post_type( 'portfolio',
       	// CPT Options
       		array(
       			'labels' => array(
       				'name' => __( 'portfolio' ),
       				'singular_name' => __( 'portfolio' )
       			),
       			'public' => true,
       			'has_archive' => true,
       			'rewrite' => array('slug' => 'portfolio'),
       		)
       	);
       }
   
       add_action( 'init', 'create_posttype' );
   
       function custom_post_type() {
   
       // Set UI labels for Custom Post Type
       	$labels = array(
       		'name'                => _x( 'portfolio', 'Post Type General Name', 'calduchstudio' ),
       		'singular_name'       => _x( 'portfolio', 'Post Type Singular Name', 'calduchstudio' ),
       		'menu_name'           => __( 'portfolio', 'calduchstudio' ),
       		'parent_item_colon'   => __( 'Parent portfolio', 'calduchstudio' ),
       		'all_items'           => __( 'All portfolio', 'calduchstudio' ),
       		'view_item'           => __( 'View portfolio', 'calduchstudio' ),
       		'add_new_item'        => __( 'Add New portfolio', 'calduchstudio' ),
       		'add_new'             => __( 'Add New', 'calduchstudio' ),
       		'edit_item'           => __( 'Edit portfolio', 'calduchstudio' ),
       		'update_item'         => __( 'Update portfolio', 'calduchstudio' ),
       		'search_items'        => __( 'Search portfolio', 'calduchstudio' ),
       		'not_found'           => __( 'Not Found', 'calduchstudio' ),
       		'not_found_in_trash'  => __( 'Not found in Trash', 'calduchstudio' ),
       	);
   
       // Set other options for Custom Post Type
   
       	$args = array(
       		'label'               => __( 'portfolio', 'calduchstudio' ),
       		'description'         => __( 'portfolio news and reviews', 'calduchstudio' ),
       		'labels'              => $labels,
       		// Features this CPT supports in Post Editor
       		'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
       		// You can associate this CPT with a taxonomy or custom taxonomy. 
       		'taxonomies'          => array( 'category' ),
       		/* A hierarchical CPT is like Pages and can have
       		* Parent and child items. A non-hierarchical CPT
       		* is like Posts.
       		*/	
       		'hierarchical'        => false,
       		'public'              => true,
       		'show_ui'             => true,
       		'show_in_menu'        => true,
       		'show_in_nav_menus'   => true,
       		'show_in_admin_bar'   => true,
       		'menu_position'       => 5,
       		'can_export'          => true,
       		'has_archive'         => true,
       		'exclude_from_search' => false,
       		'publicly_queryable'  => true,
       		'capability_type'     => 'page',
       	);
   
       	// Registering your Custom Post Type
       	register_post_type( 'portfolio', $args );
   
       }
   
       /* Hook into the 'init' action so that the function
       * Containing our post type registration is not 
       * unnecessarily executed. 
       */
   
       //* Link e4gf_events CPT to categories taxonomy
       add_action( 'init', 'sk_add_category_taxonomy_to_portfolio' );
       function sk_add_category_taxonomy_to_portfolio() {
       	register_taxonomy_for_object_type( 'category', 'portfolio' );
       }
       ```
   
 * I’ve created this “archive-portfolio.php”:
 *     ```
       <?php 
   
       /**
        *
        * @author  Ivan Ortiz & Xavier Guerrero Calduch
        */
   
       //* Template Name: Portfolio
       //* The template for displaying the portfolio of our website.
   
       get_header(); ?>
   
       <div id="primary" class="content-area">
       	<main>
   
       		<?php
   
       			$args = array( 'post_type' =>portfolio,
       						   'post_status'    => 'publish'
       						  );
   
       			$query = new WP_Query( $args ); 
   
       			$i=0;
   
       			if ( $query->have_posts()) : while ( $query->have_posts() ) : $query->the_post();
   
       				$selected = get_field('selected');
   
       				if($selected):
   
       					$image = get_field('imagen_destacados');
   
       					if( !empty($image) ):
       					?>
   
       						<article class="article-portfolio">
       							<a href="<?php the_permalink(); ?>">
       								<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
       							</a>
       						</article>
       					<?php endif; ?>
   
       				<?php endif; ?>
   
       			 	<?php endwhile; ?>
   
       			<?php endif; ?>
   
       	</main>
       </div>
   
       <?php get_footer(); ?>
       ```
   
 * The matter is that when I try to check if the selecetd field is checked or not
   in some categories it Works and in others not.
    Could somebody tell me What happens?
   I Would really appreciate it. Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [ivan76](https://wordpress.org/support/users/ivan76/)
 * (@ivan76)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/acf-truefalse-loop/#post-8209751)
 * Well I try
 * `if($selected==true)`
 * and it works
 *  Thread Starter [ivan76](https://wordpress.org/support/users/ivan76/)
 * (@ivan76)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/acf-truefalse-loop/#post-8210859)
 * No it doesn’t work. Someone can help me?
 *  Thread Starter [ivan76](https://wordpress.org/support/users/ivan76/)
 * (@ivan76)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/acf-truefalse-loop/#post-8210867)
 * Ok, I find what’s the problem but no how solve it. This script only works with
   the topics of the present year, if I select topics from other years, them aren’t
   displayed.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘ACF true/false loop’ is closed to new replies.

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 3 replies
 * 1 participant
 * Last reply from: [ivan76](https://wordpress.org/support/users/ivan76/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/acf-truefalse-loop/#post-8210867)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
