• Resolved chlara

    (@chlara)


    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)
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.