0

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 the 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!

2 Answers 2

1
<?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?

Sign up to request clarification or add additional context in comments.

2 Comments

of course, yes, this is it. I was just having a basic syntax problem.
i really cannot tell who answered first between you and Micheal, but your post was on top, so Im assuming that you posted slightly before. Thanks to both of you anyways.
1

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 ) ); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.