WordPress.org

Ready to get started?Download WordPress

Forums

Previous and Next Post in Same Taxonomy
[resolved] Can't get link to next post in same taxonomy (10 posts)

  1. Perhaps support for this plugin has stopped and a patch is preferable for this (http://core.trac.wordpress.org/ticket/17807) but I tried to use this plugin and can't get the link to show up. On the installation tab of this page - http://wordpress.org/extend/plugins/previous-and-next-post-in-same-taxonomy/installation/
    The examples are missing, so perhaps I'm not using it properly.

    I tried using:

    <?php be_next_post_link( '%link', 'See Next Case Study', true, 'case-study' ); ?>
    <?php be_next_post_link( '%link', 'See Next Case Study', true, '' ); ?>
    <?php be_next_post_link( '%link', 'See Next Case Study', true); ?>

    and also next_post_link() and can't this to work.

    I have three case studies here - http://www.rsc.com/client-type/case-study/
    and would love to display the next one when you click on one of them, so on this page for example - http://www.rsc.com/clients/cactus-club-cafe/

    Here is the full code for my single.php file - http://pastebin.com/QMmfgLYX

    If anyone has any suggestions, that would be great.

  2. Jeremy Felt
    Member
    Posted 2 years ago #

    By default, the taxonomy it uses is 'category'. It seems your last two examples would work for any category and your first example would work for any category except 'case-study'.

    Are you wanting to navigate by custom taxonomy or post tags?

    be_next_post_link( $format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category')

  3. I would like to navigate to the next case study.
    My custom post type is client and I've created a taxonomy called client-type. Only the ones marked as case-studies are clickable and lead to the single-client.php template.

    So when you are on this page - http://www.rsc.com/client-type/case-study/ and click the first client, once in there, you can then navigate to the next one.

    If I just use <?php next_post_link( '%link', 'See Next Case Study');?> I get the next client, but not necessarily the one that is in the case-study taxonomy.

  4. Jeremy Felt
    Member
    Posted 2 years ago #

    Got it. It seems like the correct syntax should then be:

    be_next_post_link( '%link', 'See Next Case Study, true, '', 'client-type' );

    That looks for the next post link by staying in the same 'cat' (badly named argument) and by using the 'client-type' taxonomy.

  5. bah, that didn't work.

    The link shows up, but then it also displays links to other clients that are not in the case study taxonomy.

    I think I may have to go with just back to case studies.

    I've left the code - <?php be_next_post_link( '%link', 'See Next Case Study', true, '', 'client-type' ); ?> in there if you want to see what it looks like Jeremy, you'll see if you click away, you'll get to clients that don't have a case study.

  6. Jeremy Felt
    Member
    Posted 2 years ago #

    Close. :)

    Do 'client' post types have more than one 'client-type' assigned to them? I.e. Case Study and Retail & Hospitality

    If that was the case, even though it's staying in the same taxonomy, it may be picking up the wrong 'client-type' as the one to stay inside. I haven't read through the code enough to know for sure, but it seems possible.

    If that is the case, you could exclude all of the other 'client-type' terms by their IDs:

    be_next_post_link( '%link', 'See Next Case Study', true, '5,6,7', 'client-type' );

    ... where term IDs 5,6,7 are associated with a client-type that is not a case study. That would be a little more annoying to manage, but could get you there.

  7. Yes the clients are in more than one taxonomy, so the Canadian Cancer Society is in the case study and non-profit taxonomy.

    I wonder if there's complication in this because I'm also using a plugin to create my CPT and taxonomies - https://github.com/jkudish/sld-custom-content-and-taxonomies

    I just tried adding the numbers of the other client types and still no joy.

  8. Jeremy Felt
    Member
    Posted 2 years ago #

    From what I'm reading in the prev/next plugin's code, that last try should be exactly what you need.

    I think using @jkudish's plugin to create the CPT and taxonomies is fine as long as 'client-type' is the right slug used to register the taxonomy.

    If there are any other plugins installed that could be using the get_{$adjacent}_join or other related filters, then that could change something.

    Seems like we need to get the patch working in core for real.

  9. I think that your right. Something in my code must be throwing this off. Since the rest of the site works, I think I'll just make do with the go back button for now and will look at this again alter. I'll mark this as resolved even though it's not for me, but it's not the plugin that's causing the error. Thanks for your help Jeremy.

  10. sporkme
    Member
    Posted 1 year ago #

    Same behavior here...

    I have a custom post type, let's call it "chapters" and a custom taxonomy called "book_category". Chapters are grouped by by unique "book_category".

    Using something like this in single-book.php (my single post template) inside a standard loop (no custom query or anything):

    <?php be_next_post_link('%link','%title',true,'','book_category'); ?>

    Gives me either no links, or links that point into other seemingly random chapters in other book_category categories.

    Is the plugin still current for 3.5.1?

    This behavior seems to be the same thing I'm seeing with the stock "next_post_link".

    Oops, forgot to include this, I'm dumping some stuff for troubleshooting:

    echo get_post_type( $post );
    echo "/" . $post->ID;
    $foo = get_the_terms($post->ID, 'book_category');
    print_r($foo);

    The output of that looks like so:

    post type/ID/cat: book/831Array ( [88] => stdClass Object ( [term_id] => 88 [name] => The Challenge to Psychoanalysis and Psychotherapy [slug] => the-challenge-to-psychoanalysis-and-psychotherapy [term_group] => 0 [term_taxonomy_id] => 48 [taxonomy] => book_category [description] => [parent] => 0 [count] => 49 [object_id] => 831 ) )

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags