Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 4, 2024 00:19
Show Gist options
  • Save zackpyle/8f34deaff62e6a1a5b41fc40dd117c0e to your computer and use it in GitHub Desktop.
Save zackpyle/8f34deaff62e6a1a5b41fc40dd117c0e to your computer and use it in GitHub Desktop.
Add URL to Beaver Builder Post module auto suggest dropdown
<?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;
}
);
@zackpyle
Copy link
Author

zackpyle commented May 3, 2024

Useful if you have a lot of posts with the same title. Example:
Screenshot 2024-05-03 at 15 14 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment