我想调出一个名为Schedule
permalink是使用post slug还是使用存储在post元数据中的值。
E、 g。/schedule/jims-schedule/
和/schedule/67sGHGj54hjs/
需要拉同一个柱子。
更多信息,让您了解我为什么这样做:
之所以有时髦的元值“id”和相应的permalink,是因为它是一个链接,你可以使用它与任何你想要的人共享,这样他们就可以调出你的时间表,所以我不想只使用slug,因为它们很容易猜测
我想调出一个名为Schedule
permalink是使用post slug还是使用存储在post元数据中的值。
E、 g。/schedule/jims-schedule/
和/schedule/67sGHGj54hjs/
需要拉同一个柱子。
更多信息,让您了解我为什么这样做:
之所以有时髦的元值“id”和相应的permalink,是因为它是一个链接,你可以使用它与任何你想要的人共享,这样他们就可以调出你的时间表,所以我不想只使用slug,因为它们很容易猜测
我在这里找到了一些好消息http://codex.wordpress.org/Plugin_API/Filter_Reference/request
我在request
像这样钩住:
add_filter( \'request\', \'alter_the_query\' );
function alter_the_query( $request ) {
$dummy_query = new WP_Query(); // the query isn\'t run if we don\'t pass any query vars
$dummy_query->parse_query( $request );
// if requesting a schedule and no posts are found with existing query vars, try the meta query
if ( $request[\'post_type\'] == \'schedule\' && !$dummy_query->have_posts() ) {
$posts = get_posts( array(
\'post_type\' => \'schedule\',
\'meta_query\' => array(
array(
\'key\' => \'wsb_schedule_id\',
\'value\' => $request[\'schedule\'],
)
),
) );
if ( count( $posts ) == 0 ) return $request; // no posts found still so return the request as is for normal processing
// a post was found, so fix the request vars and return the modified $request object for further processing
$request[\'schedule\'] = $posts[0]->post_slug;
$request[\'name\'] = $posts[0]->post_slug;
}
return $request;
}
My hook函数使用本地范围的WP\\U查询对象运行请求,如果没有返回任何计划,它将尝试元查询。如果元查询成功,它将对$request
数组,然后让Wordpress继续处理。如果元查询失败,它只会返回未经修改的$请求,以便再次进行正常处理。我不确定这将如何在时间表上得到许可,但那是另一回事。