0

this is my shotcode:

 function ctest_shortcode($atts) {
    extract(shortcode_atts(array(
        'a' => '11111'
    ), $atts));
    ob_start();
    include(locate_template('test.php'));
    return ob_get_clean();
}
add_shortcode('test', 'ctest_shortcode');

this is test php file

<?phpif ( ! defined( 'ABSPATH' ) ) {exit( 'Direct script access denied.' );}
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'mynews',
'tax_query' => array(
array(
'taxonomy' => 'newstypes',
'field' => 'tag_ID',
'terms' => array($a)  // shortcode parameter $a variable 
),),));
if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php echo get_field('link'); ?>
<?php endforeach; ?>
<?php endif;    wp_reset_postdata(); ?>

Template shows only variable a it do not showing title and act field link

code7772
  • 45
  • 9
  • `array('$a')` will create an array with one key with the literal string `$a`. If you want to use the _value_ of `$a`, just do: `array($a)` (without the single quotes) – M. Eriksson Nov 20 '18 at 06:34
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – M. Eriksson Nov 20 '18 at 06:37
  • it not showing me this fields – code7772 Nov 20 '18 at 06:41

0 Answers0