Okay
  Public Ticket #3441612
Bug / behavior in portfolio single "Next - Prev" Navigation
Closed

Comments

  •  15
    hahni started the conversation

    I found a NOT WORKING NICE AND GOOD situation by following doing:

    I use the portfolio page as a photographer and add normally one portfolio item for one shooting. But not all portfolio items will get "deeper content" - therefore i disable the item by set "Project Link" -> "Link URL"  to '#' and "Project Link" -> "Item Linking" to 'Redirect to Link URL'. Now in Portfolio Archive Page these items are "disabled" BUT in single view these items are still active and the user could go to "next - prev" DISABLED item.

    I think you should change this behavior with a better query for the "next - prev" item.

    For me the solution is to add the "portfolio tag: NO LINK" to these items and in my functions.php i added this:

    function bws_exclude_portfolio_posts( $args ) {
         $args['excluded_terms'] = array( '272' );
         return $args;
    }

    add_filter( 'kalium_adjacent_post_link_args', 'bws_exclude_portfolio_posts' );


    But now it's a manual process (like i described with the portfolio item hover state in another ticket). It should be done automatically be a better query.

  • [deleted] replied

    Hi hahni,

    I understand the point here and you are absolutely right. Right now this is not implemented but I can give you a code snippet to achieve this, here is the code you need to add to your functions.php:

    /**
     * Skip portfolio item that are external links from adjacent posts.
     */
    function kalium_portfolio_adjacent_skip_external_links( $query ) {
        if ( false !== strpos( $query, 'p.post_type = \'portfolio\'' ) ) {
            $externals = get_posts(
                [
                    'post_type' => 'portfolio',
                    'fields'    => 'ids',
                    'meta_query' => [
                        [
                            'key'   => 'item_linking',
                            'value' => 'external',
                        ]
                    ]
                ]
            );
            $query .= ' AND p.ID NOT IN (' . implode( ', ', $externals ) . ')';
        }
        return $query;
    }
    add_filter( 'get_previous_post_where', 'kalium_portfolio_adjacent_skip_external_links' );
    add_filter( 'get_next_post_where', 'kalium_portfolio_adjacent_skip_external_links' );

    If this works fine for you, we can consider including this in the theme.

  •  15
    hahni replied

    Hi Arlind

    thanks for your advise but it does not work! I added this in theme child functions.php and by adding a "var_dump" i could see that the hook is working but your changed query does not.

    You should include one more addition: "don't show items without featured image" like you do in the main query for the archive page.

    Waiting now for a new hint by you.


  •  15
    hahni replied

    I give it a new try - in one item it works: i will check the dependencies one more time and will give you feedback in the next hour.

  •  15
    hahni replied

    I made a new test but it works not stable. Actually i didn't found out the case when and when not.

  •  15
    hahni replied

    I found out that your updated query works stable BUT for working always it doesn't work - the query returns only 5 posts for not IN. Therefore it doesn't work for me without adding numberpost = -1 - now it works.

  • [deleted] replied

    Hi hahni,

    Sorry I forgot to add numberposts=-1 because it will get only 5 posts by default. You are totally right, thank you for letting me know.

    Is everything working fine with this now?

  •  15
    hahni replied

    Yes it works fine now for the moment. Thanks. I think you could close the ticket.

    Regards,
    André