如果我是你,我会使用wp\\u login\\u form函数创建你的表单,但看起来你一切都对了,也许你有理由使用手动表单。
<?php wp_login_form(); ?>
无论哪种方式,都可以使用此操作更新登录重定向,将其添加到函数中。php:
add_action( \'login_redirect\', \'custom_redirect_login\', 10, 3 );
function custom_redirect_login( $redirect_to, $request, $user )
{
$posts = get_pages( array(
\'authors\' => $user->ID
) );
if (! empty($posts) )
{
// Since the pages are listed in DESC order, the first one is the most
// recently created.
return get_permalink($posts[0]->ID);
}
else
{
// If no posts associated with the user, use default.
return $redirect_to;
}
}
如前所述,如果需要重定向到post或custom\\u post\\u类型而不是页面,则需要使用非页面特定的方法,因此这可能会更好,因为它可以更普遍地工作:
function custom_redirect_login( $redirect_to, $request, $user )
{
$posts = new WP_Query( array( \'author\' => $user->ID ) );
if ($posts->have_posts())
{
// Since the pages are listed in DESC order, the first one is the most
// recently created.
return get_permalink($posts->posts[0]->ID);
}
else
{
// If no posts associated with the user, use default.
return $redirect_to;
}
}