我的形象
我只是想为某些用户隐藏特定页面。
function remove_menus(){
// get current login user's role
$roles = wp_get_current_user()->roles;
// test role
if( in_array('administrator',$roles)){
remove_menu_page( 'edit-comments.php' ); //Posts
remove_menu_page( 'tools.php' );
remove_menu_page('edit.php');
remove_menu_page('wpcf7');
}
}
add_action( 'admin_menu', 'remove_menus' , 100 );
Run Code Online (Sandbox Code Playgroud)
这是我现在尝试过的,并且在所有页面上都可以正常工作。
我的问题是我不想显示主页 - 首页(请看我的图片)如果登录用户不是管理员。而且我想隐藏添加新的
php wordpress wordpress-theming custom-wordpress-pages wordpress-admin
http://localhost/testsite1/coder2/?id=71我有带有参数的网址id=71。
由于我正在 WordPress 中进行开发,因此我无法使用该参数$_GET['id'],因此需要使用它get_query_var('id')来访问该参数。
然而,这并没有产生任何结果。
当我通过运行代码查看所有变量时:
global $wp_query;
var_dump($wp_query->query_vars);
Run Code Online (Sandbox Code Playgroud)
...我在任何地方都看不到该id参数。
C:\wamp64\www\testsite1\wp-content\plugins\CSUKCODER\csukcoder.php:92:
array (size=64)
'page' => int 0
'pagename' => string 'coder2' (length=6)
'error' => string '' (length=0)
'm' => string '' (length=0)
'p' => int 0
'post_parent' => string '' (length=0)
'subpost' => string '' (length=0)
'subpost_id' => string '' (length=0)
'attachment' => string '' (length=0)
'attachment_id' => int 0
'name' => string 'coder2' (length=6)
'page_id' => int 0
'second' => …Run Code Online (Sandbox Code Playgroud) php wordpress wordpress-theming custom-wordpress-pages query-variables
我正在尝试在 WordPress 菜单中的任何子菜单项之后添加一个 div。我正在处理functions.php文件中的以下代码:
add_filter( 'nav_menu_link_attributes', 'SubMenuCheck', 10, 3 );
function SubMenuCheck( $atts, $item, $args ) {
if (in_array('menu-item-has-children', $item->classes)) {
$args->after = '<div class="click">+</div>';
}
return $atts;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码添加了新的 div,<div class="click">+</div>但在第一个“menu-item-has-children”类之后继续将其应用于所有父项和子项:
有谁知道为什么这是重复的?...我只希望 div 显示menu-item-has-children该类的项目。
谢谢
在我的 WordPress 中v5.6,我在作者页面中使用以下代码来显示自定义歌曲中的所有当前作者post_type的帖子。
<?php
$author_page_link = esc_url(get_author_posts_url(false, ID->user_nicename));
?>
<a href="' . $author_page_link . '?post_type=song">All Songs</a>
Run Code Online (Sandbox Code Playgroud)
上面的链接将过滤当前作者的所有歌曲,其 URL 如下:
http://www.music.com/author/current_author/?post_type=song
我想在过滤器页面中显示作者的“歌曲”和“诗歌”自定义帖子。
我尝试过下面的链接,但没有成功:
<a href="' . $author_page_link . '?post_type=song+poem">All</a>
<a href="' . $author_page_link . '?post_type=song&post_type=poem">All</a>
Run Code Online (Sandbox Code Playgroud)
如何获得一个链接来过滤单个作者的多个自定义帖子中的帖子?
更新1
我使用的是archive-song.php模板,这就是为什么song页面中只显示自定义帖子。
当将以下 URL 与 一起使用时?post_type=song+poem,archive.php仅在模板层次结构中,URL 重定向到author.php。
http://www.music.com/author/current_author/?post_type=song+poem
如果我将以下 URL 与 一起使用?post_type=song&post_type=poem,仅在模板层次结构中,则仅过滤archive.php最后的结果(可以是诗歌或歌曲,以最后一个查询为准)。post_type
http://www.music.com/author/current_author/?post_type=song&post_type=poem
更新2
这是我的作者页面(https://pastebin.com/kCrYebcD)。此页面仅显示所有帖子类型的当前作者的最新 10 篇帖子。
这是我的存档页面(https://pastebin.com/twkWn5Bc)。在这里,我想显示作者所有帖子类型的所有帖子。
我必须获得具有特定元值的帖子dynamic meta key。
这些meta key值将是:
元键中的常见文本是trend_link。所以我需要添加like operatorfor meta key.
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'projects',
'meta_query' => array(
array(
'key' => 'trend_link',
'value' => 10,
'compare' => 'LIKE'
)
)
));
Run Code Online (Sandbox Code Playgroud)
通过使用此代码,我可以like operator在meta_value.
但我需要
like operator申请meta_key。
有什么办法可以申请like operator吗meta_key?
请帮忙 !!