• Resolved bazel

    (@bazel)


    I want to exclude terms that have same name as post titles from loop. How can I pass the post titles for each post from the loop to an array outside the loop

    This is the loop for example

    <ul>
    <?php
    global $post;
    $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    and I want all the post_titles to pass to this code to exclude terms with same names as post titles

    <?php echo my_get_the_term_list( $post->ID, $taxonomy,  '', ' ', '', array($post_title1, $post_title2,) ); ?>

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • for instance:

    <ul>
    <?php global $post;
    global $all_post_titles; //?possibly needed//
    $all_post_titles = array();
    $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); $all_post_titles[] = the_title('','',false); ?></a></li>
    <?php endforeach; ?>
    </ul>

    and:

    <?php global $all_post_titles; //?possibly needed//
    echo my_get_the_term_list( $post->ID, $taxonomy,  '', ' ', '', $all_post_titles ); ?>

    depending where the second code is, you might not need to declare $all_post_titles as a global variable.

    Thread Starter bazel

    (@bazel)

    work like a charm:) Thanks a lot

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get post title foreach post in loop and pass outside the loop’ is closed to new replies.