WordPress.org

Ready to get started?Download WordPress

Forums

PHP Code Widget
[resolved] get_posts not working properly (2 posts)

  1. MultiformeIngegno
    Member
    Posted 8 months ago #

    This snippet inside a PHP code widget returns 7 links to the same post.
    Outside the widget (directly executed for example in a custom template), works properly and returns 7 different posts:

    <ul>
    <?php
    $args = array( 'posts_per_page' => 7, 'category' => 9 );
    $tag_posts = get_posts( $args ); foreach ( $tag_posts as $post ) : setup_postdata( $post ); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; wp_reset_postdata(); ?>
    </ul>

    http://wordpress.org/plugins/php-code-widget/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 7 months ago #

    You don't define $post as the global $post before attempting that code.

    Please read the FAQ and learn how PHP global and local variables work:

    http://wordpress.org/plugins/php-code-widget/faq/

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.