April 19, 2013 at 3:34 am #36338
I’m stuck and I’m hoping someone in here can help me understand what I’m doing wrong. This is a custom theme built on the sample child theme code offered here at StudioPress.
Here is my problem statement, with accompanying code…
The author shows up in archives displaying the custom post type but does not show up on the single display of that custom post type.
At the bottom of that script, you’ll notice two echo statements. The first one is displaying the author, and that’s great. Here’s that line of code:
`<?php echo 'This post was contributed by ‘ . get_the_author_meta(‘display_name’) . ”; ?> `
In the second echo, I am trying to use a variable to echo the same data, using the same function that is working in the above statement and nothing displays.
second echo’s variable: `$another_artist = get_the_author_meta(‘display_name’);`
second echo’s output code:
`<?php echo 'This post was contributed by ‘ . $another_artist . ”; ?>`
Here is a link to a single post type rendered by the above code at the development environment:
I’m truly baffled and I’m hoping that some smart person here can point me at the missing piece of the puzzle that my brain just can’t seem to find.
http://creativeconundrum.com/freshfaces/songs/blues/song-title/April 19, 2013 at 10:41 am #36396
It looks like you’re executing lines 60-67 of single-customtype.php outside of the loop. Try executing those after the “while” statement on line 71.April 19, 2013 at 11:23 am #36412
Thanks for your reply and suggestion, Dave, but those lines are not excluded. The variable $postid is being used successfully inside the loop to extract the custom fields and display them.
To show this to you (or anyone looking on), I am echoing the category slug just under the play button of the media. See this page:
Any other ideas? I’m trying to get the author into the post info area and I just can figure out why it shows in archive displays and not on the single post itself…
Archive display link:
April 19, 2013 at 11:35 am #36415
That’s because get_the_category() can execute outside of the loop. get_the_author_meta() will only work outside the loop if you explicitly pass a userID to it. Here’s one way to do it if you don’t want to move that line of code:
`get_the_author_meta(‘display_name’,get_queried_object()->post_author);`April 19, 2013 at 11:51 am #36421
Nope … moved that variable just after the while and again after the_post() and nothing has changed.
And I still would like to know why the author is missing from the post info right next to the date when it shows up in archives. That is really what I’m trying to accomplish. All the echoing inside the post itself was to see if the code knew who the author was.
April 19, 2013 at 5:08 pm #36460
Thanks Dave … with your help, I was able to sort out a method to isolate the ID for the after post in content accordion menu but I still don’t have an answer as to why the post info for my custom post type is missing information that it has for archives.
I’ll soldier on and come back with the final & functional code.
You must be logged in to reply to this topic.