Support » Fixing WordPress » How can i list posts only from Authors, excluding admins users.

  • Hi to all!

    Please, how can i list posts only from Authors, excluding Admins users?

    I want to create a page to list latest posts only from Authors users and each other only to list posts from Contributors users. An important thing is that in that pages I don’t want do list Admins users posts.

    Please, help-me.

    Many thanks!

Viewing 15 replies - 1 through 15 (of 23 total)
  • Outside the loop this should work,

    <?php
    global posts;
    
    $nonAdminPosts = get_posts(array('author' => -1, ...));
    
    ?>

    This will work outside the loop and you can add whatever arguments you want to.

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Function_Reference/query_posts

    The other option would be to alter the loop query using query_posts.

    This will work to remove specific users from the list not a user role

    Hi alphill70, thanks for response!

    Returns this error when trying the fisrt code, that is exactly what i need, outside the loop.

    The erro:
    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in C:\xampp\htdocs\demos\wp-content\themes\informecidade\home-content.php on line 92

    Any idea?

    the first line should be

    global $post;

    I left off the $ sign and there shouldn’t be an s

    my bad

    Not bad, I do the change and get new error:

    `Parse error: syntax error, unexpected ‘.’, expecting ‘)’ in C:\xampp\htdocs\demos\wp-content\themes\informecidade\home-content.php on line 94′

    then I try to correct it with the follow:

    <?php
    global $posts;
    $nonAdminPosts = get_posts(array(‘author’ => -1, ‘…’));
    ?>

    and It returns no error, but don’t show anything.

    Help me rssss

    Thank you

    to display you will need this

    <?php
    global $post;
    $nonAdminPosts = get_posts(array('author' => -1));
    
    foreach($nonAdminPosts as $nonAdmin):
    echo $nonAdmin->post_title;
    endforeach;
    ?>

    sorry i was leaving the dots so you could add more arguments.

    This should now output a list of the titles.

    Hopefully i have removed all the errors but let me know if i missed something

    You are the man hehe, functions great!

    But i also need to display the title, the name of the author, the date when the post was written and the link to the post. And I need to show 2 registers only.

    Is it asking to much ask your help in this question too? If yes I will try to search how to implement this extras.

    Thank you very much!

    The variable &nonAdmin can be used to show post_linklik, post_thumbnail and post_author like in post_title ?

    Is that correct?

    yeah that is correct if you just use the same basic format as i did then you should be able to print whatever you want.

    a reference for the indexes is here.

    WordPress $post Object Quick Reference

    use the text from the first column of the table on that page
    to display the link use

    echo "<li><a href=\" " . get_permalink() . "\">$nonAdmin->post_title</a></li>";
    
    echo get_the_post_thumbnail( $noAdmin->ID );
    
    the_author_meta( 'user_nicename', $noAdmin->ID );

    these when placed within the foreach should output what you are looking for i hope. not one hundred percent sure since a couple of these i just kind of dug up.

    ok thanks a lot, I’ll break my head a little now rsss

    Woww an new problem:

    The permanlink and the code above get the information from other post. Only the title show the right information.

    `
    echo get_the_post_thumbnail( $noAdmin->ID );
    the_author_meta( ‘user_nicename’, $noAdmin->ID );
    `

    you dropped that code into the foreach loop?

    <?php
    global $post;
    $nonAdminPosts = get_posts(array('author' => -1));
    
    foreach($nonAdminPosts as $nonAdmin):
    echo $nonAdmin->post_title;
    echo "<li><a href=\" " . get_permalink($nonAdmin->ID) . "\">$nonAdmin->post_title</a></li>";
    
    echo get_the_post_thumbnail( $noAdmin->ID );
    
    the_author_meta( 'user_nicename', $noAdmin->ID );
    endforeach;
    
    ?>

    this is what it should look like if that is what you have and it isn’t working please post the entire code you have…for this chunk

    Hey man, let’s finish this? lack a little!

    Well was missing the letter “n” in the spelling of the variable “nonAdmin” in some places. I fix it and work.

    Now the thumbnail is being displayed, the title and date also are displayed correctly.

    Isn’t correctly displayed the name of the author.

    And permanlink is pointing to the wrong place.

    The code is above:

    <?php
    	global $post;
    	$nonAdminPosts = get_posts(array('author' => -1));
    	foreach($nonAdminPosts as $nonAdmin):
    	echo "
    
    <li><a href=" ">$nonAdmin->post_title</a></li>
    	";
    	echo get_the_post_thumbnail( $nonAdmin->ID, 'thumb-size' );
    	the_author_meta( 'user_nicename', $nonAdmin->ID );
    	echo $nonAdmin->post_date;
    	endforeach;
    ?>
    echo "<a href=\"$nonAdmin->guid\"></a>";

    I believe that the guid field the $nonAdmin object will link to the correct post.

    I have used the permalink method before so i am not sure why its not working let me know if that works

    echo "<a href=\"$nonAdmin->guid\"></a>";
    the link code above function very well and link to correct place,
    the only thing is that in the status bar it shows the link structure type like: http://www.mysite.com/?p=139 – but it doesn’t matter.

    And about the author’s name that don’t show? You have any idea?

    on the user meta piece change ID to author

    That should fix the problem

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘How can i list posts only from Authors, excluding admins users.’ is closed to new replies.