[wp-trac] [WordPress Trac] #22180: Add attachments to "existing content" area in link dialog
WordPress Trac
noreply at wordpress.org
Wed Nov 20 01:51:26 UTC 2013
#22180: Add attachments to "existing content" area in link dialog
-----------------------------+------------------------------
Reporter: cgrymala | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 3.4
Severity: normal | Resolution:
Keywords: |
-----------------------------+------------------------------
Comment (by dbarlett):
As of 3.7.1 (possibly earlier), attachments are included in `$pts`, but
the query only returns objects with `post_status == publish` (attachments
have `post_status == inherit`). 3.7.0 added the `wp_link_query_args`
filter, so this works:
{{{
add_filter( 'wp_link_query_args', 'my_modify_link_query_args' );
// Query for all post statuses so attachments are returned
function my_modify_link_query_args( $query ) {
$query['post_status'] = 'any';
return $query;
}
}}}
It has a side effect of showing future, pending, and draft posts. Some
users consider that a feature, since it lets them build a series of cross-
linked posts to publish simultaneously. If you want to use direct
attachment URLs instead of attachment pages, add:
{{{
add_filter( 'wp_link_query', 'my_modify_link_query_results' );
// Link to media file URL instead of attachment page
function my_modify_link_query_results( $results, $query ) {
foreach ( $results as &$result ) {
if ( 'Media' === $result['info'] ) {
$result['permalink'] = wp_get_attachment_url(
$result['ID'] );
}
}
return $results;
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22180#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list