Wordpress 通过Slug函数获取永久链接不工作
我没有意识到WordPress在抄本中为它添加了一个本机函数,但出于某种奇怪的原因,该页面是空白的。这是否意味着该功能仍在使用中,或者该页面是错误添加的Wordpress 通过Slug函数获取永久链接不工作,wordpress,Wordpress,我没有意识到WordPress在抄本中为它添加了一个本机函数,但出于某种奇怪的原因,该页面是空白的。这是否意味着该功能仍在使用中,或者该页面是错误添加的 它是空的,因为它不存在。如果您将该函数名更改为您喜欢的任意随机名称,您仍然会看到一个空白页(当然,除非您将其更改为真实函数名)。函数get\u permalink\u by\u slug($slug,$post\u type=''){ }我真傻,当我在谷歌搜索中看到它时,我还以为它是真的呢哈哈。谢谢你的回复! // Initialize the
它是空的,因为它不存在。如果您将该函数名更改为您喜欢的任意随机名称,您仍然会看到一个空白页(当然,除非您将其更改为真实函数名)。函数get\u permalink\u by\u slug($slug,$post\u type=''){
}我真傻,当我在谷歌搜索中看到它时,我还以为它是真的呢哈哈。谢谢你的回复!
// Initialize the permalink value
$permalink = null;
// Build the arguments for WP_Query
$args = array(
'name' => $slug,
'max_num_posts' => 1
);
// If the optional argument is set, add it to the arguments array
if( '' != $post_type ) {
$args = array_merge( $args, array( 'post_type' => $post_type ) );
} // end if
// Run the query (and reset it)
$query = new WP_Query( $args );
if( $query->have_posts() ) {
$query->the_post();
$permalink = get_permalink( get_the_ID() );
} // end if
wp_reset_postdata();
return $permalink;