Skip to content
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

Open
cggit opened this issue Aug 23, 2015 · 13 comments
Open

Feature request - Show titles instead of just ID in field #10

cggit opened this issue Aug 23, 2015 · 13 comments

Comments

@cggit
Copy link

cggit commented Aug 23, 2015

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.

@monecchi
Copy link

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 <label>The Attached Post Title</label>.

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.

@tw2113
Copy link

tw2113 commented May 26, 2016

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.

  1. Titles can get long and unwieldy, combine that with a spot where you can store multiple values, and it risks getting more confusing.
  2. Easier to do the querying with the post ID. I realize you're not talking about replacing the ID completely. Except in certain types of imports when migrating content, the ID is a lot more likely to remain consistent than the title, which may be tweaked for various reasons. Once that's changed querying by title saved in meta gets broken.

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.

@monecchi
Copy link

monecchi commented Jun 1, 2016

Actually what I mean about returning a title along with the ID is:

  • Do not mess with the existing ID functionality, it is indeed the best way to keep things running consistent in the long run.

but

  • Get the title from the attached post ID and display it right bellow the search input field. It not only would add support for a "human" readable identifier, as it would enhance the user experience.

For longer titles, a simple WP function could cut that off, enough to make the post visually recognizable.

e.g:
<?php echo wp_trim_words( get_the_title(), 120, '...' ); ?>

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.

@jtsternberg
Copy link
Member

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.

@monecchi
Copy link

monecchi commented Jun 1, 2016

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

@vaclavgreif
Copy link

+1 for this, I'm using the plugins a lot and displaying post ID is not user friendly

@anmamtl
Copy link

anmamtl commented Sep 28, 2017

+1

@bake
Copy link

bake commented Nov 12, 2017

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 );

@cupcakedream
Copy link

+1

@jtsternberg
Copy link
Member

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.

@davelavoie
Copy link

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

@pgroot91
Copy link

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

@davelavoie
Copy link

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

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

No branches or pull requests

10 participants