Search code examples
phpwordpresscustom-post-typepermalinks

Beginner: How to add permalink to WP_Query multiple custom post types?


I'm making a very simple page that displays multiple post types. How do I add permalinks to the values returned from the_post_thumbnail & the_content?

    <?php
$custom_query = new WP_Query( 
    array(
    'post_type' => array('downloads', 'bjd', 'prints'),
    ) 
);
if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post();

    the_post_thumbnail('productgal-thumb');
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    the_content();

endwhile; endif; wp_reset_query();
?>

Also, if I try to place these functions in simple <div> elements to format the style it breaks the code as well.


Solution

  • simply use it like this

    <?php
    $custom_query = new WP_Query( 
        array(
        'post_type' => array('downloads', 'bjd', 'prints'),
        ) 
    );
    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('productgal-thumb'); ?> </a>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            <a href="<?php the_permalink(); ?>"><?php the_content(); ?> </a>
    <?php 
    endwhile; endif; wp_reset_query();
    ?>