Change the destination of the URLs in post.php

The post.php screen lists posts vertically in the admin area [and other post types]. Each item's post_title is a hyperlink, directly above some inline choices. Both the title link, and the Edit inline selection, redundantly go to the same destination, namely:

http[s]://{yoursite.tld}/wp-admin/post.php?post={postID}action=edit

I want to filter the post_title URL href using PHP. Specifically, I want to set a custom destination to the URL, based on metadata stored in the post. i.e post_ID:123 has post meta data:

{'custom_URL' : 'http:somesite.com'}

In post.php, how can I change the post_title hyperlink href destination URL, to a custom destination - preferably with PHP?

I'll need to somehow intercept the main query loop within post.php, because I need to do a metadata query for each of the displayed items, based on their postID. Which could be 1-200 things, generally. I could use JS to fetch the post IDs, and then do an API call(s) to the server from the browser, but I'd rather filter it from PHP before it's emitted.

Topic post-editor admin-menu admin query-posts query Wordpress

Category Web


The post title and inline "Edit" links in the posts list table at wp-admin/edit.php uses get_edit_post_link() which applies a filter hook also named get_edit_post_link, so if (I correctly understood that) you want to modify those links (URL), you can use that filter. E.g.

// Note: The callback will run anywhere, not just at wp-admin/edit.php
add_filter( 'get_edit_post_link', 'my_filter_edit_post_link', 10, 2 );
function my_filter_edit_post_link( $link, $post_id ) {
    $url = get_post_meta( $post_id, 'custom_URL', true );

    // it's all up to you on what params to add to the custom URL
    return $url ? add_query_arg( 'post', $post_id, $url ) : $link;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.