Reputation: 61
I've searched and searched, but basically what I'm trying to do is this:
I have a custom post type where there is a custom field called "loop". What I would like to do is when this field is filled out, I want to use it's content as a template part. So, for instance:
Custom Field Loop: customloop
get_template_part( 'customloop')
So, when I run my query for this post, I basically need whatever's filled out in that custom field to then be thrown into the get_template_part() so that it pulls that particular loop.
Any thoughts on how to do this?
Thanks in advance.
Upvotes: 1
Views: 233
Reputation: 1129
Yes, we can do this with the get_post_meta() function, just make sure to use the correct key name.
$loop = get_post_meta( get_the_ID(), 'customloop', true );
if($loop):
get_template_part('customloop');
else:
get_template_part('loop');
endif;
Upvotes: 1