Support

Account

Home Forums Front-end Issues Pro: Taxonomie Categories to list all Posts from

Solved

Pro: Taxonomie Categories to list all Posts from

  • Hi,

    sry, i’m a newby to ACF since a few days and today i buy’d ACF Pro.

    Please, i need informations (examples, howto’s) about how to retrieve the field term_id and other fields about choosen categories by an author on a page. I don’t know to handle the array, because the author can choose more than one category from the list.

    At the end of a custom page i want to list all posts from the choosen categories, like “more to read…”

    Hopefully someone can help me! Sry for Newbie and my bad english! THANKS!

    Have a good time! Greets, Juergen

  • My code with unknown php error:

    <h2>Beiträge auf VDT-online.de:</h2>
    
    <?php 
    
    	$terms = get_field('beitragskategorie');
    
    	if( $terms ): ?>
    
    		<ul>
    
    			<?php foreach( $terms as $term ): ?>
    				$term->term_id;
    				<h2><?php echo $term->term_id; ?></h2>
    		
    					$posts = get_posts('numberposts=10&category=' . $value . '&orderby=post_title&order=ASC');
    					foreach($posts as $post) :
    						?>
    							<li>
    								<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    							</li>
    					<?php endforeach;
    
    			<?php endforeach; ?>
    
    		</ul>
    
    	<?php endif; ?>
    
    <?php
  • Hi @jweyc01

    There are several syntax errors in your code. Could you please try the following code instead?

    <h2>Beiträge auf VDT-online.de:</h2>
    
    <?php 
    
    $terms = get_field('beitragskategorie');
    
    if( $terms ): ?>
    
        <ul>
    
        <?php foreach( $terms as $term ): ?>
    
            <h2><?php echo $term->name; ?></h2>
            
            <?php
            $value = $term->term_id;
            $the_posts = get_posts('numberposts=10&category=' . $value . '&orderby=post_title&order=ASC');
            
            foreach($the_posts as $post) :
                setup_postdata( $post )
                ?>
            
                <li>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </li>
            
            <?php endforeach; ?>
            <?php wp_reset_postdata(); ?>
    
        <?php endforeach; ?>
    
        </ul>
    
    <?php endif; ?>

    Because this issue is more related to PHP and WordPress, please visit PHP or WordPress community for further support.

    If you don’t know how to code, I suggest you learn it here: http://www.w3schools.com/php/. If you don’t have time to learn it, then I suggest you hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/, https://www.upwork.com/, or https://codeable.io/.

    I hope this helps 🙂

  • Hi @James,

    you are right. PHP is more difficult to me as other languages like VBScript, VB and Powershell. So, thanks again!

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

The topic ‘Pro: Taxonomie Categories to list all Posts from’ is closed to new replies.