• Resolved labyrinthman

    (@labyrinthman)


    I’m developing my first plugin and the shortcode is not rendering the output, instead I get the name of shortcode in square brackets.

    function easyit_travel_shortcode($atts, $content = NULL){
    
    	$atts=shortcode_atts(array(
    		'title'=>'Travel List',
    		'count'=>10,
    		'category'=>'all'
    	),$atts);
    
    	if($atts['category']=='all'){
    		$terms='';
    	}else{
    		$terms=array(
    			array(
    				'taxonomy'=>'category',
    				'fiels'	  =>'slug',
    				'terms'	  =>$atts['category']	
    			)
    		);
    	}
    
    	$args=array(
    	'post_type'=>'travels',
    	'post_status'=>'publish',
    	'orderby'	=>'due_date',
    	'order'		=>'ASC',
    	'posts_per_page'=>$atts['count'],
    	'tax_query'		=>$terms	
    		);
    
    	$travels=new WPQuery($args);
    	$output="";
    
    	if($travels->have_posts()){
    		$travels->the_post();
    
    		$start_input=get_post_meta($post->ID,'start_input',true);
    		$end_input=get_post_meta($post->ID,'end_input',true);
    		$datepicker=get_post_meta($post->ID,'datepicker',true);
    
    		$output.="<ul>";
    		$output.="<li>".$start_input."</li>";
    		$output.="</ul>";
    		return $output;
    	}
    }
    
    add_shortcode('travels','easyit_travel_shortcode');
    • This topic was modified 7 years, 1 month ago by labyrinthman.
Viewing 1 replies (of 1 total)
  • Thread Starter labyrinthman

    (@labyrinthman)

    I have figured out myself, I have had numerous mistakes.
    Here is the working code.

    function easyit_travel_shortcode($atts, $content = NULL){
    	global $post;
    	$atts=shortcode_atts(array(
    		'title'=>'Travel List',
    		'count'=>10,
    		'category'=>'all'
    	),$atts);
    
    	if($atts['category']=='all'){
    		$terms='';
    	}else{
    		$terms=array(
    			array(
    				'taxonomy'=>'category',
    				'fiels'	  =>'slug',
    				'terms'	  =>$atts['category']	
    			)
    		);
    	}
    
    	$args=array(
    	'post_type'=>'travels',
    	'post_status'=>'publish',
    	'orderby'	=>'due_date',
    	'order'		=>'ASC',
    	'posts_per_page'=>$atts['count'],
    	'tax_query'		=>$terms	
    		);
    
    	$travels=new WP_Query($args);
    	//$output="";
    
    	if($travels->have_posts()){
    
    		while($travels->have_posts()){
    		
    		$travels->the_post();
    		$start_input=get_post_meta($post->ID,'start_input',true);
    		$end_input=get_post_meta($post->ID,'end_input',true);
    		$datepicker=get_post_meta($post->ID,'datepicker',true);
    		ob_start();	?>
    		 <ul> 
    		 <li> <?php echo $start_input;?> </li>
    		 <li> <?php echo $end_input;?> </li>
    		 <li> <?php echo $datepicker;?> </li>
    		</ul> 
    	<?php }
    	wp_reset_postdata(); 
    	$content=ob_get_clean();
    	return $content;
    	
    }
    }
    
    add_shortcode('travels','easyit_travel_shortcode'); 
Viewing 1 replies (of 1 total)

The topic ‘Shortcode not rendering HTML’ is closed to new replies.