-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward.php
More file actions
44 lines (36 loc) · 1012 Bytes
/
forward.php
File metadata and controls
44 lines (36 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once('./config.php');
require_once('./lib.php');
global $wp_query;
mfn_register_types();
$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);
if (!isset($queries["news-id"]) && !isset($queries["slug"])) {
http_response_code(400);
die("Error: slug or news-id required for request");
}
$q = array(
'meta_query' => array(
'relation' => 'OR',
'news_id_clause' => array(
'key' => MFN_POST_TYPE . '_news_id',
'value' => $queries["news-id"] ?? '',
),
'news_slug' => array(
'key' => MFN_POST_TYPE . '_news_slug',
'value' => $queries["slug"] ?? '',
),
),
'lang' => '',
'post_type' => MFN_POST_TYPE
);
$query = new WP_Query($q);
$res = $query->get_posts();
$post_id = $res[0]->ID ?? '';
if (($post_id === '') || !get_permalink($post_id)) {
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
wp_redirect(get_permalink($post_id), 301);