When i lost track with all the crappy code, i decided to start all over 🙂 And so i found the solution:
<?php
// Define variables
$post_type="file";
$taxonomy = 'file-category';
$taxonomy_terms = get_terms($taxonomy);
global $current_page_id;
$current_page_id = get_the_ID();
// Start if
if ($taxonomy_terms) {
// Start Foreach
foreach ($taxonomy_terms as $taxonomy_term) {
// Start arguments for getting the posts and taxonomy
$arguments = array(
'post_type' => $post_type,
"$taxonomy" => $taxonomy_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'post_parent' => 0,
);
// End arguments
// Set query to null
$new_query = null;
// Start WP_Query
$new_query = new WP_Query($arguments);
// Start fetching posts if
if($new_query->have_posts() ) {
?>
<ul>
<?php
echo '<li><strong>' . $taxonomy_term->name . '</strong></li>';
// Start while
while($new_query->have_posts()) : $new_query->the_post();
// Get parent id
$parent_id = wpcf_pr_post_get_belongs(get_the_ID(), 'product');
// Start if $parent_id and $current page id are equal
if($parent_id == $current_page_id){
?>
<li>
<a href="https://wordpress.stackexchange.com/questions/110142/<?php echo types_render_field("file-uploads", array( "raw" => "true") ); ?>">
<span><?php the_title(); ?></span><?php echo(types_render_field("lang", array())); ?>
</a>
</li>
<?php
// End if $parent_id and $current page id are equal
}
// End while
endwhile;
?>
</ul>
<?php
// End fetching if
}
// End foreach
}
// End if
}
?>