Problems to bring content with Query in Wordpress

0

I'm having a problem with this site web on the side of ALL COURSES. I am wanting to bring in the list all the courses that I am uploading in a Post Type called course, for that I assigned some taxonomies (Edgecam, Radan, Apahacam) where I tell which brand that course belongs to. For example, the URL that attached Edgecam Standard Milling that is a course belongs to Edgecam. Although the titles of the drop-down are well placed, I do not know how to bring the titles of the post with its said link ..

The code that armes is the following:

				<?php

				$terms = get_terms( array(
				        'taxonomy'   => 'categoria-cursos',
				        'parent'     => get_queried_object()->term_id,
				        'hide_empty' => false,
				    )
				);



				foreach ($terms as $termino) {

				    $posts_array = get_posts(
				        array( 'showposts' => -1,
				               'post_type' => 'cursos',
				               'tax_query' => array(
				                   array(
				                       'taxonomy' => 'categoria-cursos',
				                       'field' => 'name',
				                       'terms' => $termino->name,
				                   )
				               )
				        )
				    );
				  	$posts_array = get_posts($posts_array);
				    if($posts_array){ 

					?>
				    <div id="accordion-container">
				        <h2 class="accordion-header ">
				            <?php echo $termino->name; ?>
				        </h2>
				        <div class="accordion-content" >
				            <ul class="icons longarrowlist">
				            	<?php foreach ($posts_array as $termino): ?>
					                <li>
					                    <a href="<?php echo get_term_link($termino); ?>">
					                        <b class="colortext">
					                            <?php echo $termino->post_title; ?>
					                        </b>
					                    </a>
					                </li>
				                <?php endforeach ?>
				            </ul>
				        </div>
				    </div>
				    <?php } ?>
				<?php } ?>
    
asked by MarianoF 23.04.2018 в 14:50
source

1 answer

0

One solution could be that for each term whose value is taken by the variable $termino you look for its posts related to the function get_posts() .

I give you an example of how this query could be, it would be missing that you iterated over the array of results of the query of posts to list them in the way that suits you.

<?php

$terms = get_terms( array(
        'taxonomy'   => 'categoria-cursos',
        'parent'     => get_queried_object()->term_id,
        'hide_empty' => false,
    )
);



foreach ($terms as $termino) {

    $posts_array = get_posts(
        array( 'showposts' => -1,
               'post_type' => 'curso',
               'tax_query' => array(
                   array(
                       'taxonomy' => 'categoria-cursos',
                       'field' => 'name',
                       'terms' => $termino->name,
                   )
               )
        )
    );?>

/*La variable $posts_array  debería ser un array con todos los posts 

relacionados, sólo tue quedaría iterar para listarlos*/

    <div id="accordion-container">
        <h2 class="accordion-header ">
            <?php echo $termino->name; ?>
        </h2>
        <div class="accordion-content" >
            <ul class="icons longarrowlist">
                <li>
                    <a href="<?php echo get_term_link($termino); ?>">
                        <b class="colortext">
                            <?php the_sub_field('texto'); ?>
                        </b>
                    </a>
                </li>
            </ul>
        </div>
    </div>
<?php } ?>

NOTE I have not been able to test the query since I do not have the structure of posts that you have built on your website and it is impossible for me to reproduce it.

    
answered by 23.04.2018 в 19:44