Title: Dynamically insert CMB2 function to custom post type loop
Last modified: May 8, 2022

---

# Dynamically insert CMB2 function to custom post type loop

 *  Resolved [chlara](https://wordpress.org/support/users/chlara/)
 * (@chlara)
 * [4 years ago](https://wordpress.org/support/topic/dynamically-insert-cmb2-function-to-custom-post-type-loop/)
 * I need to display post from custom post type name “film”, from a specific taxonomy“
   Horror.”
    Everything work fine when I type the taxonomy directly like this:
 *     ```
               <?php  $blog = array(
               'post_type'         => 'film',
               'catfilm' => 'Horror',						
               'post_status'       => 'publish',
               'posts_per_page'    =>4,
               'ignore_sticky_posts' => 1,
                );
            	?>
       ```
   
 * I need to insert dynamically the taxonomy with CMB2, so I change the code like
   this, but no luck. The post failed to appear:
    My CMB2 function:
 *     ```
       	$cmb_tvseries->add_field( array(
       		'name'        => esc_html__( 'Sub Title', 'cmb2' ),
       		'description' => esc_html__( 'Subtitle for your main Title', 'cmb2' ),
       		'id'          => 'mytheme_catfilm',
       		'type'        => 'text',
       	) );
       ```
   
 * My loop change to:
 *     ```
             <?php $blog = array(
           	'post_type'         => 'film',
           	'catfilm' => '<?php echo ( get_post_meta( get_the_ID(), "mytheme_catfilm", true ) ); ?>',						
           	'post_status'       => 'publish',
           	'posts_per_page'    =>4,
           	'ignore_sticky_posts' => 1,
           	);
           	?>
       ```
   
 *  I am newbie on php. Please help.

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

 *  Thread Starter [chlara](https://wordpress.org/support/users/chlara/)
 * (@chlara)
 * [4 years ago](https://wordpress.org/support/topic/dynamically-insert-cmb2-function-to-custom-post-type-loop/#post-15626000)
 * NOTED: I am using text, so the user need to type the category.
 *  Thread Starter [chlara](https://wordpress.org/support/users/chlara/)
 * (@chlara)
 * [4 years ago](https://wordpress.org/support/topic/dynamically-insert-cmb2-function-to-custom-post-type-loop/#post-15626186)
 * nevermind, prolem solved

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

The topic ‘Dynamically insert CMB2 function to custom post type loop’ is closed 
to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

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

 * 2 replies
 * 1 participant
 * Last reply from: [chlara](https://wordpress.org/support/users/chlara/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/dynamically-insert-cmb2-function-to-custom-post-type-loop/#post-15626186)
 * Status: resolved