Support » Plugins » Hacks » Problem making widget to display newest posts form category

  • Resolved pedjas


    Well, I am trying to create widget that displays last posts from selected category. Everzthing works fine exept it always displays title and link to last post on blog, not slected post. Here is some code:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Problem is this: get_posts() does return needed posts properly, and in a foreach loop I prepare each post using setup_postdata(). However, the_permalink() and the_title() always return values from the last post on forum, not from post prepared using setup_postdata().

    the_excerpt() does return proper exceprt form current post I want to display. So I get pretty messy result.

    I’ve spent substantial time trying to figure out what I am doing wrong, but I cannot tell.

    Any help?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I did not realize that posting code is forbidden. I do not see any purpose of this user unfriendly requirement. Ok, I understand hundred or so lines are unreadable, but allowing just ten lines, that is useless. After all, forum should warn and do not allow posting message.

    I tried to use pastebin as required, I hope it will do the job:

    Whole method code is at

    Here is problematic part:

    $m_posts = get_posts($m_args);
    		foreach ($m_posts as $m_post) {
    		<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    		<?php //echo the_excerpt(); ?>

    forum should warn and do not allow posting message.

    You did read these before posting, didn’t you?

    No I did not. I read rules years ago when I first came to and I do not expect I have to check rules to see if something changed, especially to look for something such unreasonable. 10 lines? Then, posting any code should be banned as ten lines is usually not enough.

    Rule is not what upset me, but that forum did not warn me that I posted too much code and did not refuse to save post, so I did not notice that was the problem until several hours later.

    I solved my problem by abandoning the_permalink() and the_title(). They do not work on the contrary what Codex says (and even provides example). So, there must be a bug in API or Codex.

    I managed to get what I needed by using get_permalink() and get_the_title() instead.

    They do not work

    I’ve never had a problem with them on dozens of WordPress sites.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem making widget to display newest posts form category’ is closed to new replies.