Skip to content

Commit 06b9efb

Browse files
authored
Merge pull request #199 from PRX/segment_redirect
Add media url filter to detect segments
2 parents 2236cba + 2295a5a commit 06b9efb

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

wp-content/plugins/tw-endpoint-helper/tw-endpoint-helper.php

+23-4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
367367
'name' => 'node',
368368
'replace' => 'node/',
369369
),
370+
array(
371+
'name' => 'file',
372+
'replace' => 'file/',
373+
),
370374
array(
371375
'name' => 'taxonomy',
372376
'replace' => 'taxonomy/term/',
@@ -388,8 +392,9 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
388392
// Return only if something is found.
389393
if ( $id && $type ) {
390394

391-
$wp_id = '';
392-
$wp_type = '';
395+
$wp_id = '';
396+
$wp_type = '';
397+
$wp_meta_key = 'nid';
393398

394399
// Convert type from node to post_type if needed.
395400
switch ( $type ) {
@@ -402,6 +407,11 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
402407
$wp_type = 'post';
403408
break;
404409

410+
case 'media':
411+
$wp_type = 'segment';
412+
$wp_meta_key = 'fid';
413+
break;
414+
405415
default:
406416
$wp_type = $type;
407417
break;
@@ -410,15 +420,20 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
410420
// Get WP Posts by node id.
411421
$s_args = array(
412422
'post_type' => $wp_type,
413-
'meta_key' => 'nid',
423+
'meta_key' => $wp_meta_key,
414424
'meta_value' => $id,
425+
'fields' => 'ids',
426+
'posts_per_page' => 1,
427+
'no_found_rows' => true,
428+
'update_post_meta_cache' => false,
429+
'update_post_term_cache' => false
415430
);
416431

417432
$posts = get_posts( $s_args );
418433

419434
if ( $posts && ! is_wp_error( $posts ) ) {
420435

421-
$wp_id = $posts[0]->ID;
436+
$wp_id = $posts[0];
422437
}
423438

424439
if ( $wp_id && $wp_type ) {
@@ -435,6 +450,7 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
435450
return false;
436451
}
437452

453+
438454
/**
439455
* Get post by slug.
440456
*
@@ -448,6 +464,9 @@ function _peh_get_object_by_slug( $slug, $extra_args = array() ) {
448464
'name' => $slug,
449465
'post_status' => 'publish',
450466
'posts_per_page' => 1,
467+
'no_found_rows' => true,
468+
'update_post_meta_cache' => false,
469+
'update_post_term_cache' => false
451470
);
452471

453472
if ( $extra_args ) {

0 commit comments

Comments
 (0)