First you need to get the categories of the current post, and then you can ‘exclude’ them by sending them through via the get_categories
arguments array as $args['exclude']
.
get_categories()
uses get_terms()
, you can see the list of available arguments you can use here.
We get the post terms with wp_get_post_terms()
and make sure that we only get an array of ids and not an array of objects by passing it array("fields" => "ids") );
$args = array( 'parent' => 779 );
//Get the current post categories
$post_categories = wp_get_post_terms( get_the_ID(), 'category', array("fields" => "ids") );
if ( ! empty( $post_categories ) ) {
//Here we make use of the exclude argument
$args['exclude'] = $post_categories;
}
$categories = get_categories( $args );
Then you can just loop through your categories with your second snippet as you were earlier.
foreach ( $categories as $category ) {
$value[] = array(
'field_5cd186302ef1c' => $category->name,
);
};
return $value;