New Landing How can we help? Themeforest Theme Support Dante Related projects – basic concept behind the order they are shown in?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Posted in: Dante
  • #243019
    sarawh
    Member
    Post count: 3

    Hi,
    I apologize if this is an obvious question but I can´t get my related projects to show up in all the places they should be. They seem to show up on a portfolio item if they share the same category – but not all the time. Sometimes on portfolio item A) the related project C) will show but on portfolio item C) the related project A) will not. So although A and C share the same categories, only one will show the other.
    Can you tell me how it is supposed to work? Thanks.

    Best regards, Sara

    #243560
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    Please test this code, please activate your child theme – inside the child theme folder there is a file called functions.php, please copy this code to that and then re-test:

        /* PORTFOLIO RELATED POSTS
        ================================================== */
        function sf_portfolio_related_posts( $post_id, $item_count = 3 ) {
            $query = new WP_Query();
            $terms = wp_get_object_terms( $post_id, 'portfolio-category' );
            if ( count( $terms ) ) {
            	$post_ids = array();
            	$term_categories = array();
            	
            	foreach ($terms as $term) {
            		$term_categories[] = $term->term_id;
            		$post_ids[] = get_objects_in_term( $term->term_id, 'portfolio-category' );
            	}
    
                $index = array_search( $post_id, $post_ids );
                if ( $index !== false ) {
                    unset( $post_ids[ $index ] );
                }
                
                $args  = array(
                    'post_type'      => 'portfolio',
                    'post__not_in'	 => array( $post_id ),
                    'tax_query' => array(
                    		array(
                    			'taxonomy' => 'portfolio-category',
                    			'field' => 'slug',
                    			'operator' => 'OR',
                    			'terms' => $term_categories
                    		)
                    ),
                    'posts_per_page' => $item_count
                );
                $query = new WP_Query( $args );
            }
    
            // Return our results in query form
            return $query;
        }

    Thanks.

    #245071
    sarawh
    Member
    Post count: 3

    @David
    Sorry, this hasn´t worked: only the 3 latest posts get displayed as related posts, regardless of whether they are actually related by category or not.
    Ideally I´d like to add the title and subtitle to the related posts too – does that all get too complicated so that it would be better to add the RPs using the page builder? (intelligence ends after html and css here 😉
    Thanks.
    Sara

    #245651
    David Martin – Support
    Moderator
    Post count: 20834

    Hi Sara,

    The above works on categories only. It will get projects related if they share the same categories.

    It’s not possible to do by title and subtitle. You can increase the amount of output projects by changing the count $item_count = 3 number.

    Thanks.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register