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.