I'm having a problem displaying my custom post type in a WP_query loop, under my post thumbnail image I keep seeing signs (">) like I'm not closing the tags properly. Also under that image my first custom field where I show a price is not showing at all, but I know it's there and it works properly if I use

highlight_string("<?php\n\$ACF-fields =\n" . var_export(get_fields(), true) . ";\n?>");

I see the price value.

This is the loop:

$args = array(
    "post_type" => "piso"
$the_query = new WP_Query( $args );

<?php if( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<div class="pisos-grid-item-wrap <?php $comprar_alquilar ?>"

    <a href="<?php the_permalink(); ?>">
        <img src="<?php the_post_thumbnail( 'post-thumbnail', array('width'=>'270') ); ?>">

    <h1> <?php echo $precio ?> € </h1>
    <h2> <?php the_title(); ?> </h2>
    <h3> <?php echo $donde ?> </h3>


<?php endwhile; endif; ?>

Also, this is probably worth a new question, but is there an easy way to add a custom field as a class of my main post wrap?

  • 1
    Check the syntax in the first block of the code you've forgotten to markdown. – Max Yudin May 22 '17 at 10:08
  • 1
    Markdown? You could write it so I can accept it. – Sergi May 22 '17 at 10:13
  • 1
    The markdown in the question is already fixed. Now you check the code you've written there. – Max Yudin May 22 '17 at 10:20
  • 1
    It doesn't change anything. It's still not closed properly, you've actually now left the main div open, but it displays the same anyway. – Sergi May 22 '17 at 10:24
  • 1
    I didn't change the code, only formatting. – Max Yudin May 22 '17 at 10:29

Try and remove the_post_thumbnail function from the img tag. On its own the_post_thumbnail prints out the img tag so there seems to be two img tag ending in your script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.