URL with suggestions of posts and pages

Support Meta Box AIO URL with suggestions of posts and pagesResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #28797
    Noisy BirdNoisy Bird
    Participant

    Hello,

    I have created a CPT to drive a slider on a homepage.

    So the CPT for each single slide has:
    - A post title
    - An excerpt
    - A featured image (thumbnail)

    All of those data are pulled by the slider (which is dynamic)

    I would like to add a URL custom field, but I would like to know if it is possible that the URL field can show suggestions of internal URLs (internal pages or posts) as the user types inside?

    Thank you!

    #28814
    Long NguyenLong Nguyen
    Moderator

    Hi Noisy,

    Thank you for getting in touch.

    The field URL does not support to show suggestion posts or users. You can use the field type post and user then get the permalink via the WordPress function
    - For post: get_the_permalink()
    - For user: get_author_posts_url()

    #28823
    Noisy BirdNoisy Bird
    Participant

    Hi Long,

    Thank you for your reply, I am not very familiar with php yet, I think I might need the page or post URL stored into a variable, that I can grab with the dynamic Slider plugin. For now, if I type manually or copy paste the URL into the URL custom field, it works. But I wonder if it is possible to select the page like on the post field, and obtain its URL, while still staying in the WordPress admin backend, because then I need to grab the URL variable from the Smart Slider dynamic slide.

    #28837
    Long NguyenLong Nguyen
    Moderator

    Hi,

    There is no prebuilt option to populate the URL from the post field automatically. You can add this custom code to the file functions.php in the child theme folder or use Code Snippets to apply it.

    add_action( 'rwmb_FieldPostID_after_save_field', function( $null, $field, $new, $old, $object_id ) {
        $post_url = get_the_permalink( $new );
        update_post_meta( $object_id, 'FieldPostURL', $post_url );
    }, 20, 5 );

    The code helps you to update the field URL value from the field post value after clicking Publish/Update the current post.

    Remember to replace the FieldPostID, FieldPostURL with your field post and URL ID. And register or place the field URL before the field post. Screen record https://share.getcloudapp.com/ApuzA81K

    #28839
    Noisy BirdNoisy Bird
    Participant

    Wow, fantastic, thank you very much!

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