WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] More help with connecting posts one level apart (11 posts)

  1. remtheory
    Member
    Posted 2 years ago #

    Hi there! So, I've poured through the documentation and have continuously failed at trying different ways to get this to render. I thought perhaps the Loops page would provide some insight but I couldn't get anything to display, which perhaps is due to my lack of understanding. So, here's the sitch...

    I've got a custom post type called Products, another custom post type called Brands and another custom post type called Stores. Right now, Brands display both the products and the stores, which is great. I've got that working like a charm. And I've got products and store pages linking to their related brands. Also, lovely. But what I'd love to do is have my Product page list the related stores and standards that are attached to that product.

    Here's my site, so you can see what I'm talking about:
    http://www.kind-eye.com/brand/100-pure/ is the brand page, looking lovely.
    http://www.kind-eye.com/product/100-pure-fruit-pigmented-eye-shadow/ is a product page, and ideally it would replicate the same information from the brand page for Store & Standards.

    Thanks for any help!

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    It would be useful to see your p2p_register_connection_type() calls.

    Paste them on http://gist.github.com with a link back here.

  3. remtheory
    Member
    Posted 2 years ago #

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    For the "Other Products in This Brand" tab, you can use get_related():

    https://github.com/scribu/wp-posts-to-posts/wiki/Related-posts

    For the "Find Where to Buy" tab, you'll first need to get the connected brand. Afterwards it's the same code as on the brand page.

  5. remtheory
    Member
    Posted 2 years ago #

    Sigh. Clearly this is beyond me, no luck in getting the "Other Products in this Brand" to work. Am I just supposed to add $related = p2p_type( 'brand_to_product' )->get_related( get_queried_object_id() );, or is it the whole shebang, more like https://gist.github.com/1895238?

  6. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    $related = p2p_type( 'brand_to_product' )->get_related( get_queried_object_id() );

    should work. Here's the corrected gist: https://gist.github.com/1895302

  7. remtheory
    Member
    Posted 2 years ago #

    Weird, i'm just getting nothing. not even an error, just zero results. every product is definitely associated with a brand and i've been able to populate the brand just fine, but still no luck on the products that are connected to that brand. I've left my theme functions php file completely as is and am using the Allow PHP plugin to toss in the code and embed it in a template view. Maybe my plugin hackery is getting out of control?

  8. remtheory
    Member
    Posted 2 years ago #

    Alrighty, apparently I had to remove some of the calls I had, which I think freaked it out. Related products appear! Onto figuring out the next chunk. Thank you sooo much!

  9. remtheory
    Member
    Posted 2 years ago #

    Where's that pesky donate button of yours so I can show you some cash love?

  10. scribu
    Member
    Plugin Author

    Posted 2 years ago #

  11. hept27
    Member
    Posted 1 year ago #

    Just a note for anyone who happens upon this page and can't get the solution to work for them. Make sure that if you are on a post that would be "related" in the sense that you are looking for, that there are more posts than just that one that are related. I thought the code wasn't working but I was on the one the page for the only post that was related and of course it doesn't show up as related so I thought it wasn't working.

    Hope that helps somebody!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic