Wordpres PHP Help Needed

by 8 replies
10
I am trying to get the ID of a particular post that is replicated onto various blogsites in a network.

The code below works to give me the blog ID, but, the blog URL is shown onscreen without the echo command being invoked. What do I need to change?

I have been unable to get it to work without including the blog URL from bloginfo.

Code:
 $ varname = url_to_postid(bloginfo('url') . '/category-slug/post-slug/');
#programming #needed #php #wordpres
  • Hi Kirk

    How are the sites related? By that I mean are they all part of the
    same multisite install or are they completely separate blogs? If
    separate blogs, are the blogs all part of YOUR network or do they
    include web 2.0 blogs, for example?

    Steve
    • [ 1 ] Thanks
    • [1] reply
    • Hi Steve,

      The blogs are all a part of the same multisite network.

      In this script, I have used the 'switch_to_blog()' function to switch to the main blog (using switch_to_blog(1) ) and then used a selectbox with a foreach loop in it and the 'setup_postdata()' function to build a list of posts from a specific category.

      Then I use the 'restore_current_blog()' function to return to the current blog where the admin can save a copy of the post from the main blog.

      The posts the admin is selecting from could best be described as product sales pages, and the blog admin will be earning a commission on each one he or she sells.

      They select the post from the main blog, and then it is saved to the catalog post spot on their blog. That is how they are related.
  • If you're assigning the output of a function to a variable, the function should return its result. What you're describing is indicative of a function that echoes its result. Verify that your 'url_to_postid' function returns its result.
    • [ 1 ] Thanks
    • [1] reply
    • Thanks Steve ...

      RFT16 explained it even further. I had tried to figure that out by reading the codex, and experimenting, but I absolutely did not see the difference until you two pointed it out. RFT16 specifically told me which did what. I tried to figure that out from the codex, but the answer never sunk in until now.

      Thanks again!
  • the problem here is probably with your 'bloginfo' function.

    WP generally provides two variants of a single function - one that returns the value and another that echoes the output.

    In this case 'bloginfo( parameter )' ECHOS the value of the parameter.
    Whereas 'get_bloginfo( parameter )' RETURNS the value of the parameter.

    Hope this helps.

    Cheers.
    • [ 1 ] Thanks
    • [1] reply
    • That was the problem. I needed 'get_bloginfo()' instead of 'bloginfo()'

      I had read both of the codex pages, and tried their examples. You gave me the understanding that Wordpress didn't. I guess the folks that write the codex have varying skills, so they are not always as clear in their explanations as beginners like me need.

      Many thanks!
  • For the first problem, go to your web page in your browser, right click on the 'x' icon, select properties and read the url that comes up, ensure that the image you want displayed is named exactly as written and located where expected.
    Second problem...let me read it again, i'll get back to you...

    Right, can't help much without seeing the rest of the script, displaying images next to each would be done using html or css, but there's not enough info to advise on the rest of the problem, also, i'm not familiar with wp
  • Give me a call 1-800-219-1314 EXT 0 I'll give you a hand i don't mind.

    let me know if you gotten it fixed or not.

    WILL-

Next Topics on Trending Feed

  • 10

    I am trying to get the ID of a particular post that is replicated onto various blogsites in a network. The code below works to give me the blog ID, but, the blog URL is shown onscreen without the echo command being invoked. What do I need to change?