• Hi All,

    I am working on multisite where i am using url to retrieve the post id. This works fine when i am passing url from current blog. But when the url comes from same network site but from different blog at that time i am trying blog swictching using following snippet.

    switch_to_blog($blog_id);
    $post_id = url_to_postid( $permalink );
    restore_current_blog();

    But it gives me always zero even i am switching correct blog. Anyone know any alternative for same will be happy?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Ignore the other post. I’m slow today.

    You’re not defining a post anywhere in there, you’re just saying “Get a post!”

    Is that the WHOLE code block you’re using?

    Prasad

    (@bagraoprasad)

    Try these

    global $blog_id;
    $current_blog_details = get_blog_details( array( 'blog_id' => $blog_id ) );
    echo $current_blog_details->blogname;

    I hope it works well 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPresss function url_to_postid() returns 0 in multisite’ is closed to new replies.