Home › Forums › Pro Support › Custom field under title custom post type
- This topic has 9 replies, 2 voices, and was last updated 2 years, 6 months ago by
elvin.
-
AuthorPosts
-
March 24, 2021 at 5:28 am #28436
Robert
Participantwhy?
March 24, 2021 at 5:29 am #28438Robert
Participantok, i typed ‘why’ because my post got rejected…. Too many words?
March 24, 2021 at 5:33 am #28440Robert
Participantcant submit anything which is more then just a single line of tekst….
is there a restriction on how many words a post can have?March 24, 2021 at 10:46 am #28457Robert
ParticipantThe question:
After searching and tweaking, fiddling and trying, I decided to ask my question on the forum 🙂
I have 2 custom post types;
– Speaker
– Abstracts (something the speaker said)The abstracts are shown in a 3 column grid on the homepage.
My client asked if it’s possible to show the link to the speaker, under the title of the abstract. (as I would with a category or a tag).
Normally I would connect those via a category or a tag, but as these are both custom post types, it’s not possible (out of the box) to make a relation between these 2 post types.
In the ‘Abstract’ post, I made a custom field (link) with the Generatepress Elements/hooks, so I can select the url to the speaker, and show it on that particular ‘Abstract’ below the content.
Now, my question;
How can I show this same link (to the speaker of this abstract) under the title of the post type abstract?Examples:
On the 3 column grid of this homepage, https://www.digitalhumanitiestilburg.com/The way the abstract should look (title, category – we are not going to use images here, so text only and no cards or any fancy layout)
https://www.digitalhumanitiestilburg.com/speakers/I would like the same speaker-link as in: https://www.digitalhumanitiestilburg.com/abstracts/finding-the-human-in-the-dark-forest-perspectives-on-user-practices-outside-of-social-media-platforms/ (speaker is below the content, in the yellow box).
I have also tried to place this same code below via a custom hook in generatepress, but it didn’t work (I cannot select the appropriate place for it to be shown.)
The code I used for the custom link is this (and i’d like to ‘get’ the same link to show under the title of the abstracts):
<div class=”speaker-wrapper”>
<?php$link = get_field(‘speaker_in_abstract’);
if( $link ):
$link_url = $link[‘url’];
$link_title = $link[‘title’];
$link_target = $link[‘target’] ? $link[‘target’] : ‘_self’;
?><div class=”speaker-info”>
Speaker:
” target=”<?php echo esc_attr( $link_target ); ?>”><?php echo esc_html( $link_title ); ?>
</div><?php endif; ?>
</div>Hope you can help me out!
Thanks in advance!March 24, 2021 at 4:31 pm #28473elvin
ModeratorHi there,
First off, we apologize for the inconveniences caused by the forums. We’re trying to fix it.
If it’s too much trouble to use, we can continue with email-based support by sending your concern on your contact page.
https://wpshowposts.com/contact/As for inserting codes after the WPSP’s title, you can use
wpsp_after_title
hook.I believe you don’t have to do any special conditions assuming your custom fields are only assigned to the custom post types you mentioned as their output will only display with posts that have custom posts with custom fields that have value.
March 25, 2021 at 1:14 am #28492Robert
ParticipantHi Elvin,
I think Tom sorted the problem out, so the forum is fine for now, thanks!
yes, i figured out so far that the wpsp_after_title wss the way to go, but as i’m learning php, i’m not quite sure how to implement it.
normally i would use the elements- hooks option, where i can set the hook, but I cannot set the display rules for the hook wpsp_after_title to be shownor should i implement this in another way?
March 25, 2021 at 2:53 am #28500Robert
ParticipantYessssss! I made it work with an action 🙂
here is the code:
add_action( ‘wpsp_after_title’, ‘dht_custom_abstract_link’ );
function dht_custom_abstract_link() {
$link = get_field(‘speaker_in_abstract’);
if( $link ):
$link_url = $link[‘url’];
$link_title = $link[‘title’];
$link_target = $link[‘target’] ? $link[‘target’] : ‘_self’;
?><div class=”speaker-info”>
<p>Speaker: </p>” target=”<?php echo esc_attr( $link_target ); ?>”><?php echo esc_html( $link_title ); ?>
</div>
<?php endif;
}March 25, 2021 at 4:46 pm #28519elvin
ModeratorYou can actually use the Hook Element for this but you have to make sure you have to select “Custom Hook” on the hook dropdown and type in
wpsp_after_title
.You can then add in the contents of the
dht_custom_abstract_link()
. Just make sure “Execute PHP” is enabled and pay close attention to<?php
?>
delimiters.March 26, 2021 at 4:03 am #28560Robert
ParticipantHi Elvin,
I allready fixed it with the action (works as well), but im still curious: if I use an element hook, what should I select at the display rules location?
There is no option to select for a custom post type, or am i missing something?
Ticket can be closed, because it’s resolved! Thanks for the help (again!)March 29, 2021 at 12:05 am #28639elvin
ModeratorI allready fixed it with the action (works as well), but im still curious: if I use an element hook, what should I select at the display rules location?
It should be where you’re using the WPSP list.
That’s weird.
But to be honest, things like this are best done w/ child theme’s functions.php or a Code Snippets plugin.
Glad you got it sorted. No problem. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.