Use $variable to fill in wp_query post_type
-
I’m not sure if this is the best way to do this. Essentially I have two services I offer which I’ve made as two custom post types. The “archive” page (which I’ve just created as a regular Page in WordPress) is identical except for a few things. I figured rather than have two separate Pages with the same code I would create a Template page that has the same code. The problem is I have a
WP_query
that needs differentpost_type
names.So I figured the best way to do this was create an
if
statement depending on which service it is and have variables for each service. But it doesn’t seem to be working. This is what I have:<?php $post_type = 'video'; $work_link = the_field('video_link'); $thumb = the_post_thumbnail( 'video-thumb' ); ?>
And:
<?php $query = new WP_Query( array( 'post_type' => ' . $post_type . ', 'posts_per_page' => -1 ) ); ?>
Any help would be appreciated. I’m not an expert when it comes to PHP so please spell it out for me.
Bonus if anyone knows how I can return the
$thumb
variable (and allow WordPress to execute the PHP code). Is it as simple as<?php return $thumb; ?>
. Again, no PHP expert.Thanks!
- The topic ‘Use $variable to fill in wp_query post_type’ is closed to new replies.