We're merging with GenerateBlocks! Learn more here.

[Resolved] Custom field under title custom post type

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Custom field under title custom post type

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #28436
    Robert
    Participant

    why?

    #28438
    Robert
    Participant

    ok, i typed ‘why’ because my post got rejected…. Too many words?

    #28440
    Robert
    Participant

    cant submit anything which is more then just a single line of tekst….
    is there a restriction on how many words a post can have?

    #28457
    Robert
    Participant

    The 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!

    #28473
    elvin
    Moderator

    Hi 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.

    #28492
    Robert
    Participant

    Hi 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 shown

    or should i implement this in another way?

    #28500
    Robert
    Participant

    Yessssss! 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;
    }

    #28519
    elvin
    Moderator

    You 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.

    #28560
    Robert
    Participant

    Hi 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!)

    #28639
    elvin
    Moderator

    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?

    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. 😀

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.