开发者

Storing php value into variable, and display in Wordpress loop

I am using a wordpress plugin called advanced custom fields that basically creates custom write panels on the backend, and gives you php shortcodes to insert into your template files.

It looks like the following:

<?php echo get_field('video-slug'); ?>

This will return a slug value that I need for 开发者_如何学Cthe wordpress loop.

My wordpress loop is as follows:

<?php $loop = new WP_Query( array( 'post_type' => 'videos', 'artist_name' => 'HERE IS WHERE I WANT THE SLUG', 'post_child' => 0, 'posts_per_page' => 5 ) ); ?>
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <li>
            CONTENT HERE
            </li>

        <?php endwhile; ?>

If you notice, the first line of the loop requires that slug that was created above. I cannot simply enter <?php echo get_field('video-slug'); ?> into the loop because it will cause a php error. Perhaps I can create a variable and then put that into the loop?

Basically, I need to know how to take a php generated value, perhaps store it in a variable, and then use that variable in my loop as follows: 'artist_name' => '$variable' or something like this. Thanks!


<?php $loop = new WP_Query( array( 'post_type' => 'videos', 'artist_name' => get_field('video-slug'), 'post_child' => 0, 'posts_per_page' => 5 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <li>
        CONTENT HERE
    </li>

<?php endwhile; ?>

If the get_field('video-slug') returns something, then the code above should work.. Does it?


Can you do this

<?php $loop = new WP_Query( array( 'post_type' => 'videos', 'artist_name' => get_field('video-slug'), 'post_child' => 0, 'posts_per_page' => 5 ) ); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜