WordPress.org

Ready to get started?Download WordPress

Forums

How to showcase TWO different posts using > query_posts (14 posts)

  1. gs06
    Member
    Posted 7 years ago #

    Hi guys,

    sorry for the multiple questions :)

    I would like to showcase TWO different posts on my welcome page

    in my home.php I placed the query_posts tag
    but i get only ONE post
    here is the tag i am using:

    <?php
    query_posts('p=21,43');
    ?>

    any suggestions how i get both post id=21, and below it post id=43 ?

    Thank you !

  2. I don't believe you can use query_posts() for that (mutliple posts), but I'm not sure.

    Just use this instead:

    $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID='21' OR ID='43'");

  3. gs06
    Member
    Posted 7 years ago #

    Thanks

    tried, but got jibrish

    i used the code as follows:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <?php
    $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID='21' OR ID='43'");
    ?>

    this is not on my index page but home.php
    what am i doing wrong ?

  4. tried, but got jibrish

    Okay, what was it?

  5. gs06
    Member
    Posted 7 years ago #

    yea exactlly
    got jibrish as well
    how do i incoperate your code
    to my home.php page ?

  6. Michael Bishop

    Posted 7 years ago #

    He means what was the jibrish exactly?

  7. gs06
    Member
    Posted 7 years ago #

    the 2 posts are there but then
    i get a bunch of strange error-posts :

    Category: Uncategorized

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comment_approved = '1'' at line 1]
    SELECT COUNT(comment_ID) FROM wp_comments WHERE comment_post_ID = AND comment_approved = '1';
    0 Comments

    , Edit This

    Category: Uncategorized

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comment_approved = '1'' at line 1]
    SELECT COUNT(comment_ID) FROM wp_comments WHERE comment_post_ID = AND comment_approved = '1';
    0 Comments

    , Edit This

    Category: Uncategorized

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comment_approved = '1'' at line 1]
    SELECT COUNT(comment_ID) FROM wp_comments WHERE comment_post_ID = AND comment_approved = '1';
    0 Comments

    , Edit This

    Category: Uncategorized

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comment_approved = '1'' at line 1]
    SELECT COUNT(comment_ID) FROM wp_comments WHERE comment_post_ID = AND comment_approved = '1';

  8. Please post the contents of your entire home.php or whatever: http://pastecode.com

  9. gs06
    Member
    Posted 7 years ago #

    sure

    here you go :

    http://pastecode.com/3993

  10. You need to add the code as I mentioned above. ;)

    http://pastecode.com/4030

  11. gs06
    Member
    Posted 7 years ago #

    Thanks Viper007Bond.
    i tried it
    but this line >>
    <?php else : ?>
    keeps coming as error > > parse error, unexpected $
    i tried to delete the line
    no good

    tried to delete

    <?php else : ?>

    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php endif ?>

    no good

    suggestions ?

  12. gs06
    Member
    Posted 7 years ago #

    anyone ?

  13. giles
    Member
    Posted 7 years ago #

    I had this very same problem ... it was fixed very easily ... i went through disabling all my plugins one by one .. the 3rd plugin i disabled fixed it .. it was my Adhesive plugin that was messing it up.
    http://www.redalt.com/downloads/ was where it was from .. and now doesn't seem to be kept up to date .. so if i need sticky posts i won't be using it any more !

  14. amylooo
    Member
    Posted 7 years ago #

    I have the same error on the index page at http://www.amyloo.com/clipoftheweek

    Like one of the first posters in this thread, it happened after I added a query_post -- in my case to exclude a particular category of posts from the index.

    Like the just-previous poster, I isolated the troublemaker. It's the theme; when I revert to the basic theme, the error goes away. Problem is the thememaker says my question is beyond his scope of support http://forums.wpthemes.info/comments.php?DiscussionID=126/

    So now what? I'll likely end up starting over with a new theme based on the default rather than modifying a theme that doesn't look anything like what I ended up with anyway! But for a quick fix, I thought it might be worth asking if anybody has any ideas. Thanks.

    /amyloo

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.