Last active
May 4, 2024 00:19
-
-
Save zackpyle/8f34deaff62e6a1a5b41fc40dd117c0e to your computer and use it in GitHub Desktop.
Add URL to Beaver Builder Post module auto suggest dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Modify the data returned for BB post module auto suggest queries to include post URLs | |
add_filter('fl_builder_auto_suggest_posts_lookup', function ( $data ) { | |
foreach ( $data as $key => $post ) { | |
$post_object = get_post( $post['value'] ); | |
// If the post object exists, append the URL path to the title | |
if ( $post_object ) { | |
$permalink = get_permalink( $post['value'] ); | |
// Remove the main site URL from the permalink to make it shorter | |
$path = str_replace( home_url(), '', $permalink ); | |
// Append the path to the title | |
$data[ $key ]['name'] .= ' - ' . $path; | |
} | |
} | |
return $data; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful if you have a lot of posts with the same title. Example: