Reputation: 303
I feel like there is a really simple solution to this problem. However, after trying to solve it for about 3 hours unsuccessfully, I humbly come to you.
How would I get and display the contents (specifically custom field data) of a specific band entry (using its ID or title or slug) inside of a regular post? (see diagram below)
(source: thisnewband.com)
.
We have to provide the ID/title/slug so that it knows what band post's content to display
[band id="21"]
) (added inside post content)band-id
where you can input the ID of the band)Shortcode
WP_Query
to query post with type=band and ID="21".functions.php
query_post
with no luck)Custom Field
WP_Query
and had the ID
in the array pull from the custom field.Whether it's by using a shortcode, custom field, or even a new widget, it would be easiest if one could:
get_template_part('band-block');
to echo this code (either in Post Template or Shortcode via functions.php)Thanks for your help! Let me know if you'd like to see any of my code.
Upvotes: 2
Views: 5610
Reputation: 113
Add this loop after the normal loop...
<?php /* Display all the author's posts from the custom post type ('band') */ ?>
<?php
$authorid = get_the_author_meta( ID, $userID );
$args4=array('author'=>$authorid,'post_type'=>'band', 'numberposts'=> -1);
$cquery4=new WP_Query($args4);
if($cquery4->have_posts()):
while($cquery4->have_posts()):
$cquery4->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<p><?php the_title();?></p>
</a>
<?
endwhile;
wp_reset_postdata();
endif;
?>
Upvotes: 0
Reputation: 11
I knew you have found a solution for your problem, but for others i will give them an other solution:
You can query by ID, no problem. Look at these: http://www.advancedcustomfields.com/resources/field-types/relationship/ But you have to check in the custom field "return format" the box "Post IDs". Then it works perfectly well.
Sorry for my bad english ;) Cheers
Upvotes: 1
Reputation: 303
With some amazing help from Hobo, I was able to come up with a solution!
The main problem was with trying to query by 'ID'. No matter what we tried, it just never worked well. (It could be the way that the Advanced Custom Fields stored the ID field contents.)
post-band-name
and created with the Advanced Custom Fields plugin.)Upvotes: 0