WordPress.org

Ready to get started?Download WordPress

Forums

Ambrosite Next/Previous Post Link Plus
[resolved] I believe I found a bug. (2 posts)

  1. Doodlebee
    Member
    Posted 1 year ago #

    I'm using this to move through a custom post type series, where they are in the same custom taxonomy. The format for the links is like so:

    previous_post_link_plus(array('format' => '&laquo %link', 'in_same_tax' => 'true',
                                                  'link' => '%title'));
      next_post_link_plus(array('format' => '%link »', 'in_same_tax' => 'true',
                                                  'link' => '%title'));

    My post type is called "courses".

    When I add the "'post_type' => 'courses'" to the array, the links do not show up (and I get no error messages or warnings). If I remove that, it works fine. I don't know where the bug is in that, so I just left that part out of the array and it seems to be working fine anyway.

    BUT

    with the "in same tax" part in there (set to true), the links didn't show up and I got multiple error messages about the taxonomy array being invalid.

    When I looked in the plugin code, I found this:

    99			if ( $in_same_tax && !$in_same_cat ) {
    100				if ( $in_same_tax === true ) {

    at line 100, you have "===". If you change that to "==" it resolves the multiple error messages, and the links still work just fine.

    Just thought I'd share.

    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 10 months ago #

    That is not a bug; '===' is the PHP strong equality operator:

    http://php.net/manual/en/language.operators.comparison.php

    The purpose of that construct in my plugin is to allow to user to pass either the name of a custom taxonomy, or the Boolean value 'true', using the same parameter.

    The problem with your sample code is that you are not supposed to surround the value 'true' with quotation marks. The word 'true' in PHP is a Boolean literal, not a string:

    http://php.net/manual/en/language.types.boolean.php

    What happened in your case was that the string 'true' failed the strong equality check, and fell through to the section of the code that handles the string as a taxonomy name (which is why you were getting the error about the taxonomy being invalid, since you do not have a custom taxonomy called 'true'). By making the change you made, you removed the strong equality check, therefore it stayed in the section of the code that auto-detects the taxonomy.

    Tl;dr If you had done it like this, it would have worked:

    previous_post_link_plus(array('format' => '&laquo %link', 'in_same_tax' => true, 'link' => '%title'));
    next_post_link_plus(array('format' => '%link »', 'in_same_tax' => true, 'link' => '%title'));

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.