How to get the current category with custom posts

The good basic technique to go from specifics to more general context is to look at the calls you already have. You already call single_cat_title(), which somehow knows current category, right? If you look inside you will see it passes call to single_term_title(). And how does that one in turn knows? $term = get_queried_object(); So … Read more

What is the best way to build home pages with a lot of sections for distributable themes [closed]

Due to historical context implementation of static front pages in WordPress is, simply put, a horror. This is not something it was meant to do originally and the way it was bolted on at a certain point is opposite of smooth. Under these constraints it would be hard to impossible to say what would be … Read more

Dynamic assign a custom template to custom post type posts

locate_template search template only in themes then to use a file outside themes, you can use the filter template_include like that add_filter(“template_include”, function ($template) { $post = get_queried_object(); if ( is_single() && (“features” === $post->post_type) ) { // absolute path to the template file $template = __DIR__ . “/../../template/my_features_template.php”; } return $template; });

How can I load 2 random pages?

You can redirect users from home page to random page with this code (paste it to your functions.php) function my_homepage_redirect() { if ( is_home() || is_front_page() ){ $page = get_posts( [ ‘post_type’ => ‘post’, ‘posts_per_page’ => 1, ‘category’ => 1, // your category ID ‘orderby’ => ‘rand’, ‘fields’ => ‘ids’ ] ); if ( empty( … Read more