Skip to content

Give posts (any type) higher priority in link search results #63683

Closed

Description

@richtabor

In LinkControl you can search for content existing on your site. This is great, but I did find that attachments were surfaced higher in search results than posts matching the search requirements.

I propose that pages and posts of all type are prioritized in the search results, above all others. It's much more likely to link to pages and posts, than to attachments.

Visual

Maintain a consistent layout and style across patterns while

Activity

  1. added
    [Type] Enhancement
    [Feature] Link Editing
    on Jul 17, 2024
  2. moved this to Needs development in Polishon Jul 17, 2024
  3. noisysocks commented on Jul 24, 2024

    @noisysocks
    Member

    I propose that pages and posts of all type are prioritized in the search results, above all others.

    Take this too literally and we'll cause a regression of #56478 😀 I think we want to prioritise posts and pages but not always place them above every other result. It's important that users can easily link to tags and categories especially from the Navigation block.

  4. richtabor commented on Jul 24, 2024

    @richtabor
    MemberAuthor

    I'd say you are likely to search for and link a page many times more likely than a tag or category archive.

    I would say given a page, tag, and attachment matched with patterns, the page should be first in that list.

    Perhaps deprioritizing attachments would meet the expectations better?

  5. noisysocks commented on Jul 25, 2024

    @noisysocks
    Member

    Yeah in your example screenshot I'd expect Composing with patterns to be first but if you searched for "patterns-1" I'd expect patterns-1 to appear first.

    The key thing to bear in mind is that we don't want to regress #56478 as that bug made creating some types of navigation basically impossible.

    I think giving posts a slight (25%? need to play with the exact number) boost and attachments a slight penalty (25%?) should work.

  6. richtabor commented on Jul 27, 2024

    @richtabor
    MemberAuthor

    I'm down for trying that.

  7. fabiankaegy commented on Dec 3, 2024

    @fabiankaegy
    Member

    After updating to WordPress 6.7 this is something we've heard several client teams complain about. They are having a much harder time finding the actual relevant content than they did before the update which is impacting their workflows.

    In all honesty I would love an option to remove attachments from the results altogether. On most sites that simply isn't something that editors need to do. And if so they can add the link manually 🤔

    The exploration of giving less prominence to attachments sounds like a good first step though 👍

    I'm also going to add the [Type] Regression label to this since the search here used to be much better than it is now in 6.7

  8. added
    [Type] Regression
    and removed
    [Type] Enhancement
    on Dec 3, 2024
  9. SainathPoojary commented on Dec 9, 2024

    @SainathPoojary
    Member

    Hey @noisysocks,

    I explored implementing the 25% boost for post types and the 25% penalty for attachments. Here are my findings:

    Initially, I directly applied the adjustments like this:

    // Boost for post types, penalty for attachments
    if (result.kind === 'post-type') {
        relevanceScore *= 1.25;
    } else if (result.kind === 'media') {
        relevanceScore *= 0.75;
    }

    However, I noticed that the recently added sorting logic was penalizing results with longer titles. This was due to the score calculation formula:

    (exactMatchingTokens.length / titleTokens.length) * 10;
    const subMatchScore = subMatchingTokens.length / titleTokens.length;

    To address this, I modified the logic to depend on the length of the search query instead of the title:

    const exactMatchScore = 
        (exactMatchingTokens.length / searchTokens.length) * 10;
    
    const subMatchScore = 
        subMatchingTokens.length / searchTokens.length;

    This worked better, but exact string matches were still being ranked lower than post types. To resolve this, I added a significant boost for exact title matches to ensure they appear at the top:

    // Significant boost for exact title matches
    if (result.title.toLowerCase() === search.toLowerCase()) {
        relevanceScore *= 100;
    }

    Currently, the ranking logic is functioning as follows (I’ll share a video to demonstrate this). I’ve also retested the previously implemented fixes to ensure they aren’t breaking anything, and everything appears to be working as expected.

    Do you think this approach is good to proceed with, or would you suggest any additional changes? If everything looks good, I’ll raise a PR with these updates.

    Thanks!

    Complete code:

    export function sortResults( results: SearchResult[], search: string ) {
    	const searchTokens = tokenize( search );
    
    	const scores = {};
    	for ( const result of results ) {
    		if ( result.title ) {
    			const titleTokens = tokenize( result.title );
    			const exactMatchingTokens = titleTokens.filter( ( titleToken ) =>
    				searchTokens.some(
    					( searchToken ) => titleToken === searchToken
    				)
    			);
    			const subMatchingTokens = titleTokens.filter( ( titleToken ) =>
    				searchTokens.some(
    					( searchToken ) =>
    						titleToken !== searchToken &&
    						titleToken.includes( searchToken )
    				)
    			);
    
    			// The score is a combination of exact matches and sub-matches.
    			// More weight is given to exact matches, as they are more relevant (e.g. "cat" vs "caterpillar").
    			// Diving by the total number of tokens in the title normalizes the score and skews
    			// the results towards shorter titles.
    			const exactMatchScore =
    				( exactMatchingTokens.length / searchTokens.length ) * 10;
    
    			const subMatchScore =
    				subMatchingTokens.length / searchTokens.length;
    
    			scores[ result.id ] = exactMatchScore + subMatchScore;
    
    			let relevanceScore = exactMatchScore + subMatchScore;
    
    			// Boost for post types, penalty for attachments
    			if ( result.kind === 'post-type' ) {
    				relevanceScore *= 1.25;
    			} else if ( result.kind === 'media' ) {
    				relevanceScore *= 0.75;
    			}
    
    			// Significant boost for exact title matches
    			if ( result.title.toLowerCase() === search.toLowerCase() ) {
    				relevanceScore *= 100;
    			}
    
    			scores[ result.id ] = relevanceScore;
    		} else {
    			scores[ result.id ] = 0;
    		}
    	}
    
    	return results.sort( ( a, b ) => scores[ b.id ] - scores[ a.id ] );
    }

    Preview

    Current Implementation:

    Screen.Recording.2024-12-09.at.7.50.25.PM.mov

    Tested whether the current changes break the previously added fix in #67367

    Screen.Recording.2024-12-09.at.7.51.50.PM.mov
  10. getdave commented on Dec 10, 2024

    @getdave
    Contributor

    There's #67563 which has a working prioritisation of Posts. I would love for some reviews on that and/or code contributions to tweak this towards what we need.

  11. SainathPoojary commented on Dec 10, 2024

    @SainathPoojary
    Member

    Hi @getdave,

    I tested the solution in #67563, and it seems to work well for me overall. Initially, I thought it might cause the regression mentioned in #56478, but after further testing, I was unable to reproduce the issue.

    Specifically, I created multiple posts using the following commands:

    wp post create --post_title="The Ultimate Adventure Awaits" --post_status=publish --post_type=post
    wp post create --post_title="An Unexpected Adventure Begins" --post_status=publish --post_type=post
    wp post create --post_title="Adventure Through the Mountains" --post_status=publish --post_type=post
    wp post create --post_title="A Day Full of Adventure and Fun" --post_status=publish --post_type=post
    wp post create --post_title="Lost in an Adventure Wonderland" --post_status=publish --post_type=post
    wp post create --post_title="The Adventure of a Lifetime" --post_status=publish --post_type=post
    wp post create --post_title="Embarking on a New Adventure" --post_status=publish --post_type=post
    wp post create --post_title="Adventure Calls from Afar" --post_status=publish --post_type=post
    wp post create --post_title="Exploring the Jungle of Adventure" --post_status=publish --post_type=post
    wp post create --post_title="The Secret Adventure Revealed" --post_status=publish --post_type=post
    wp post create --post_title="Adventure by the Ocean Waves" --post_status=publish --post_type=post
    wp post create --post_title="A Thrilling Adventure Awaits You" --post_status=publish --post_type=post
    wp post create --post_title="The Magical World of Adventure" --post_status=publish --post_type=post
    wp post create --post_title="Adventure in the Unknown Realms" --post_status=publish --post_type=post
    wp post create --post_title="An Epic Adventure Through Time" --post_status=publish --post_type=post
    wp post create --post_title="Adventure in the Heart of the Forest" --post_status=publish --post_type=post
    wp post create --post_title="The Great Adventure Journey" --post_status=publish --post_type=post
    wp post create --post_title="Adventure with Friends and Family" --post_status=publish --post_type=post
    wp post create --post_title="Chasing the Spirit of Adventure" --post_status=publish --post_type=post
    wp post create --post_title="An Unforgettable Adventure Experience" --post_status=publish --post_type=post
    

    Additionally created 1 category and 1 attachment with name "Adventure"

    In my tests, I believe the sorting behavior appears to work correctly.

    2024-12-10.21-15-04.mp4

    @noisysocks, could you confirm if the test cases for this scenario accurately validate the issue described in #56478?

    I’d appreciate your thoughts on this, @getdave.

  12. t-hamano commented on Dec 16, 2024

    @t-hamano
    Contributor

    I'm beginning to think that an approach that relies solely on weighting may not be able to fully solve this problem. Search results are always limited to a maximum of 20 results, but what users want to prioritize can vary infinitely depending on user preferences and site content.

    Maybe the UI itself needs some improvements, like the following: Please excuse the clumsy design 😅

    Add a button to load more search results:

    Image

    Allow search results to be filtered by type:

    Image

    @WordPress/gutenberg-design Any ideas?

  13. 7 remaining items

  14. tonx commented on May 13, 2025

    @tonx

    Recent WordPress VIP customer interactions have prompted me to provide feedback on the recent change to the link selection feature in WordPress 6.7. The link search now displays categories and attachments alongside posts.

    From our experience at WordPress VIP, working alongside large-scale WordPress implementations that serve hundreds of editors daily, we've observed that this change creates significant workflow challenges. Customers have reported that the expanded search results make it more difficult to quickly locate and link to other relevant posts, which is their primary use case for the link selector.

    While we understand the intention to provide more comprehensive linking options, in enterprise publishing environments where editors create dozens of interlinked articles daily, the added categories and attachments in search results introduce unnecessary friction to a previously streamlined process.

    We hope to bring visibility to this change/issue and consider potential solutions:

    • Making this behavior configurable via a filter or setting
    • Adjusting the default search prioritization to favor posts over other content types
    • Adding a simple way for editors to filter results by content type

    Thank you for your consideration and all the work that goes into improving WordPress.

  15. roborourke commented on Jan 29, 2026

    @roborourke
    Contributor

    We've had similar reports from clients at Human Made, a news site can have lots of similarly named articles and attachments so since 6.7 the link search is seen as a regression by them.

    I think these suggestions from others in this thread are what will make it useful again:

    • having a better default in terms of weighting results in favour of content
    • tabs to choose between content, terms and media
    • load more results button
  16. devisan commented on Sep 1, 2026

    @devisan

    I have many searches where I can't surface the post at all. Every post with a related tag and every relevant attachment fills the search results and the post isn't there. Is anyone actually searching the name of a tag and then hoping to find all the posts related to it? I guess that's a plausible workflow, but it shouldn't crowd out posts.

  17. graylaurenm commented on Sep 2, 2026

    @graylaurenm
    Contributor

    @rickcurran @swissky @devisan – Following up on my previous comment & code: we made a plugin workaround for this. Apologies for not responding to the comment I was tagged in (over a year ago). In case it helps, you can find it here: https://wordpress.org/plugins/exclude-link-suggestions/

    It excludes attachments by default, and now has options to exclude custom post types and taxonomies as well.

  18. devisan commented on Sep 2, 2026

    @devisan

    Thank you @graylaurenm. I found this yesterday after leaving my comment and it's working well for me.

  19. jeryj commented on Sep 22, 2026

    @jeryj
    Contributor

    I have a combination of ideas to fix this. I'll open a PR this week. Here's the core issues I see with the current situation and how to get out of it.

    1. Results are crowded out.

    The issue of results being crowded out of a search are because fetchLinkSuggestions fetches 20 results from four different buckets: post, term, post-format, and attachment. Then it sorts these results by giving each a score and returning the highest scored 20.

    AFAIK, there isn't a reason to only return the top 20. I don't think there's a technical limitation here. So, let's unbind the search result limit. If there are 80 good matches, return all 80. Most of the time there will not be 80 matches or there will be throwaways (for example, right now a page will match based on body content even if the title does not contain a string match).

    2. Pages/Posts (content) are generally preferred, but others (Taxonomies, Attachments, etc) are valid.

    Combined with the above, we can add an option for preferred ordering results. By default, it can be: `["post", "term", "attachment", "post-format" ]. A search item can only break out of this ordering if it's truly a better result. For example, with the search term "note", an attachment named "Note" should rank higher than a page named "Denoted".

    To improve finding navigation links, we should also be able to pass a specific subtype into this. On the default Page link, it should be able to return Pages as the first band of results, making it [{type: "post", subType: "page"}, "post", "term", "attachment", "post-format" ].

    3. Introduce filters for searching a specific content type

    Based on this four bucket search masquerading as one search, I don't think it's possible to do a truly paged search without fetching everything in the database (-1 perPage), ordering, and segmenting by page. So, fetchLinkSuggestions offering a page option alongside the open ended search won't work. You'll having missing results from the lower results of each bucket. Paged results only work when they are within a specific type.

    I think fixes 1 and 2 will address most websites, but for a really large site with lots of content types, they can use filter to choose a specific type from a dropdown ("page", "post", "category", "tag", "attachment", (any other custom post type, taxonomy etc)). Then, we can have paged or "load more" results.

  20. added a commit that references this issue on Oct 1, 2026
    e87a726
  21. added a commit that references this issue on Oct 1, 2026
    03432f8
  22. added a commit that references this issue on Oct 2, 2026
    6b5d6c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Feature] Link Editing[Status] In Progress[Type] Regression

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions