admin管理员组文章数量:1317909
I've got a local Wordpress install that I've tried to make customisable by users, so it only shows pages from categories they have selected. I've used the code that I've found in the thread How to Set an Individual Homepage for Each User? and while it works, it breaks the menu on every page, it just dissapears.
Example before: .png
And After: .png
Any help would be appreciated. Thank you in advance.
I've got a local Wordpress install that I've tried to make customisable by users, so it only shows pages from categories they have selected. I've used the code that I've found in the thread How to Set an Individual Homepage for Each User? and while it works, it breaks the menu on every page, it just dissapears.
Example before: https://i.sstatic/dVvLb.png
And After: https://i.sstatic/aNqWX.png
Any help would be appreciated. Thank you in advance.
Share Improve this question asked Oct 30, 2020 at 10:47 Zan KraljZan Kralj 133 bronze badges1 Answer
Reset to default 0It's important to add guard clauses to prevent modification of other queries. (For example, menus). We are trying to modify the main query here, so we should bail if this is not the main query.
function my_get_posts( $query ) {
// Bail if this is not the main query.
if ( ! $query->is_main_query() ) {
return;
}
// Other guard clauses to ensure we don't affect queries unintentionally.
// Sounds like you are just trying to target the homepage, so we could check for that too.
if ( ! is_home() ) {
return;
}
// We only need to modify the query for logged in users.
if ( ! is_user_logged_in() ) {
return;
}
// Modify the query as needed...
}
add_action( 'pre_get_posts', 'my_get_posts' ); // Note that pre_get_posts is an action, not a filter.
本文标签: customizationCategory selectable homepage
版权声明:本文标题:customization - Category selectable homepage 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742026667a2415671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论