• hi

    I have a code to set breadcrumbs with higher priority

    I want to add a condition to it
    If SELECT PRIMARY was empty
    Run this code

    add_filter( 'aioseo_breadcrumbs_output', 'aioseo_breadcrumbs_output_start' );
    function aioseo_breadcrumbs_output_start( $display ) {
    	if ( ! is_singular( 'post' ) ) {
    		return $display;
    	}
    
    	add_filter( 'wp_get_object_terms', 'aioseo_breadcrumbs_trail_change_term' );
    
    	return $display;
    }
    
    function aioseo_breadcrumbs_trail_change_term( $terms ) {
    	remove_filter( 'wp_get_object_terms', 'aioseo_breadcrumbs_trail_change_term' );
    
    	$hasArticlesTerm = current( wp_list_filter( $terms, [ 'slug' => 'game' ] ) );
    	if ( ! empty( $hasArticlesTerm ) ) {
    		foreach ( $terms as $key => $term ) {
    			if (
    				( 0 === $term->parent && $term->term_id !== $hasArticlesTerm->term_id ) ||
    				( 0 < $term->parent && $term->parent !== $hasArticlesTerm->term_id )
    			) {
    				unset( $terms[ $key ] );
    			}
    		}
    	}
    
    	return $terms;
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @gamefa,

    You should be able to do something like this –

    $metaData = aioseo()->meta->metaData->getMetaData( $postId );
    
    if ( empty( $metaData->primary_term ) ) {
        // Do whatever you need to do here.
    }

    Let me know if that works!

    Thread Starter kasra naraghi

    (@gamefa)

    @arnaudbroes

    Unfortunately no
    Does not work

    $metaData = aioseo()->meta->metaData->getMetaData( $postId );
    if ( empty( $metaData->primary_term ) )
    {
        add_filter( 'aioseo_breadcrumbs_output', 'aioseo_breadcrumbs_output_start' );
    		function aioseo_breadcrumbs_output_start( $display )
    		{
    			if ( ! is_singular( 'post' ) )
    			{
    			return $display;
    			}
    		add_filter( 'wp_get_object_terms', 'aioseo_breadcrumbs_trail_change_term' );
    		return $display;
    		}
    	function aioseo_breadcrumbs_trail_change_term( $terms )
    	{
    	remove_filter( 'wp_get_object_terms', 'aioseo_breadcrumbs_trail_change_term' );
    	$hasArticlesTerm = current( wp_list_filter( $terms, [ 'slug' => 'game' ] ) );
    		if ( ! empty( $hasArticlesTerm ) )
    		{
    			foreach ( $terms as $key => $term )
    			{
    				if (( 0 === $term->parent && $term->term_id !== $hasArticlesTerm->term_id ) || ( 0 < $term->parent && $term->parent !== $hasArticlesTerm->term_id ))
    				{
    					unset( $terms[ $key ] );
    				}
    			}
    		}
    
    	return $terms;
    	}
    }
    
    
    

    • This reply was modified 10 months, 1 week ago by kasra naraghi.
    Thread Starter kasra naraghi

    (@gamefa)

    If this code is inactive

    SELECT PRIMARY works fine

    But if the code is active

    SELECT PRIMARY is not displayed

    If we had a prioritization system to display categories
    It would be much better
    We do not need this code

    Plugin Support Prabhat

    (@prabhatrai)

    Hey @gamefa,

    We’re closing this thread as you’ve reached out to us via our website as well. We’ll review the code and continue the conversation there.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘breadcrumbs PRIMARY’ is closed to new replies.