-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request - Show titles instead of just ID in field #10
Comments
I like the idea of displaying a title. Perhaps, after the ID has been attached to the field, the plugin could return a simple label right bellow the search input field with the post title such as It makes no sense at all for a user to only see the ID, nobody knows by memory each post ID, so displaying a title should save you a click on the search button just to recall the name of the attached post. |
I am not the final authority on the plugin nor do I know why the decision was made this way, but I have to believe it was done this way for a couple reasons.
More than willing to be wrong, or have ideas proposed that perhaps makes the best of both worlds. I just wanted to bring up my thoughts on why it is what it is now. |
Actually what I mean about returning a title along with the ID is:
but
For longer titles, a simple WP function could cut that off, enough to make the post visually recognizable. e.g: The plugin is great as is, and perhaps the suggested functionality is not that relevant for the "wp admin" level peeps, for most site owners who lack wp authoring skills it'd be a considerable nice enhancement. |
It'd be fairly trivial to add, and is in place in several of the other field-types which do something similar. Just need to get the time. |
@jtsternberg that would be great. I've tried to bring that functionality myself, but as I'm not a developer, I'm afraid I lack the skills to make it right. |
+1 for this, I'm using the plugins a lot and displaying post ID is not user friendly |
+1 |
I usually just add a list of the posts after the input. This obviously isn't updated live. add_action( 'cmb2_render_post_search_text', function( $field ) {
$args = [
'post_type' => $field->args['post_type'],
'post_count' => -1,
'orderby' => 'post__in',
'post__in' => explode( ',', $field->escaped_value ),
];
$posts = get_posts( $args );
foreach ( $posts as $post ) {
printf( '%d: <a href="%s">%s</a><br>', $post->ID, get_edit_post_link( $post->ID ), $post->post_title );
}
}, 20 ); |
+1 |
I'd recommend switching to the CMB2 Attached Posts Field, as it has the same search feature, but also other UI enhancements like drag & drop and filtering. |
Hi everyone, I've forked the repo and added support for displaying the Title instead of the ID along with a few other improvements. If you want to use it simply go to https://github.com/EP4/CMB2-Post-Search-field |
@davelavoie can you update the read-me with the changes in your fork? For people it is easier to distinguish all those forks from one and another. |
Sure, I've just updated it. |
Would be helpful to get a post title in the field instead of id for content editors.
I think the field should still return the id so maybe using JS you could replace the id with a title and little x to delete it. Similar to how tags work in WordPress and Stackoverflow.
The text was updated successfully, but these errors were encountered: