Home Support General HivePress hivepress()->router->get_current_route_name() isn’t working.

hivepress()->router->get_current_route_name() isn’t working.

  • Author
    Posts
  • suncatcher

    Hello ihor,
    I tried to check the current page route name (listing view page) using hivepress()->router->get_current_route_name() in child theme’ functions.php.

    var_dump( hivepress()->router->get_current_route_name() ); NULL returned.

    if( hivepress()->router->get_current_route_name() === 'listing_view_page' ){
        ...
    }

    Broken page returned. (just a few lines of texts, a layout just like a single post)

    Tested both on my local host and live host, got the same result.

    I didn’t find any solution here on this forum regarding this.

    Could you please kindly check?

    Thanks.

    ihor developer

    Please try checking it on template_redirect action, if you check it earlier the route may not be initialized yet.

    suncatcher

    Thank you ihor, it worked!

    Another question.

    I changed the listing rewrite slug to ‘rewritten-slug’ in my child theme’s functions.php.

    But what I got with this hivepress()->get_config('post_types')['listing']['rewrite']['slug'] was still ‘listing’, instead of ‘rewritten-slug’.

    Thanks again.

    ihor developer

    Please change this via the hivepress/v1/post_types filter, then if you refresh permalinks there will be a new slug.

    suncatcher

    Hi ihor,
    Thank you for your reply.

    I think I didn’t make my question clear.. What I want is I have already changed the post type via hivepress/v1/post_types, but I want to get the post type because I need to use it somewhere important as I don’t want to hard code it.

    By the way, is there any function or filter I can use to get the ‘listing name’ and ‘listing slug’ or the listing id within child theme’s functions.php?

    Thanks again.

    ihor developer

    This one is correct, it gets the post types config after all the filters:

    hivepress()->get_config('post_types')

    It may not work only if your filter is added after you get this config. Sorry, there’s no per-listing filter, you can try customizing the output (templates) instead or edit listings in the database.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.