1
votes

Thanks for taking a look at my question.

I have created a custom post that is called "movies" I have managed to get it to show a list of movies and I have created a single page called "single-movies.php"

I'm also using a plugin called Advanced Custom Fields to add fields, the problem is when I click on a movie to get more details, it shows all the movies details when I only want the one I clicked on.

So for example if I have 4 movies added it with the custom post, it will show all 4 movie details in the single-movies page, example:

mydomain.com/movies/avangers-2

The above url is suppose to only show me details from the avengers 2 but it shows me every single custom post I have added.

Here's the code for single-movies.php

  <?php
    $args = array(
             'post_type' => 'movies',
             'post_status' => 'publish');

    $loop = new WP_Query( $args );

    if( $loop->have_posts() ):

    while( $loop->have_posts() ): $loop->the_post();?>

    <div class="movie-details">
     <h2><?php the_title(); ?></h2>
     <img href="<?php the_field('movie_img_url'); ?>" />
     <?php the_field('movie_synopsis', $post_id); ?>
     <?php the_field('movie_analysis', $post_id); ?>
    </div>

  <?php
     endwhile;
    endif;
  ?>

</div>

Is this a problem with the query? or maybe Advanced Custom Fields is not able to display single records.

I really hope this question makes sense. I look forward to hearing from you, thank you in advance.

1
Your query is looping through all of the custom movie posts, if you include an ID of the post in the array it will limit it to that ID. Or remove the loop and just put <?php the_title(); ?> and see if that only shows the title of the selected film. - Tony Hensler

1 Answers

0
votes

The below will query for one post. However, I think you are asking to get all of the posts, but get custom field info when a post is clicked on, am I right? You would need javascript for that whether it's vanilla or you use JQuery. I can help further if you clarify :)

$args = array(
    'post_type' => 'movies',
    'numberposts' => 1,
    'post_status' => 'publish'
);