Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:00:27+00:00 2026-05-26T11:00:27+00:00

I am running a script to get some posts from a database. Here is

  • 0

I am running a script to get some posts from a database.
Here is the script:

private function getItems()
    {
        $this->dbConnect($detailsTable);
        mysql_select_db(DB_NAME);
        mysql_query('SET NAMES utf8');
        mysql_query('SET CHARACTER SET utf8');

        $result = mysql_query('SELECT * 
        FROM wp_posts, wp_term_relationships,wp_term_taxonomy 
        WHERE wp_posts.post_status = "publish"  
        AND wp_term_relationships.object_id = id
        AND wp_term_taxonomy.taxonomy= "category"
        AND !(wp_term_taxonomy.term_taxonomy_id = 11)
        AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
        ORDER BY wp_posts.post_date DESC LIMIT 25', LINK);
        mysql_close(LINK);

        $items = '';
        while($row = @mysql_fetch_array($result))
        {
            $title = UTFayar($row['post_title']);
            $content = UTFayar($row['post_content']);

            $items .= '<item id="'.$row["ID"].'">
                <title><![CDATA['.$title.']]></title>
                <description><![CDATA['. $content .']]></description>
                <pubDate>'.date('D, j M Y H:i:s T', strtotime($row['post_date'])).'</pubDate>
                <category>'.$row['post_category'].'</category>
            </item>';
        }
        $items .= '</channel>
                </rss>';

        return $items;
    }

The problem is that some posts are in 3+ categories.
So I get a wrong result, I get same post 3+ times successively. I need that this post even if is at more then one category to be showed in my rss only 1 time.

EIDTED:

Here is right code, if some one will need it:

    private function getItems()
    {
        $this->dbConnect($detailsTable);
        mysql_select_db(DB_NAME);
        mysql_query('SET NAMES utf8');
        mysql_query('SET CHARACTER SET utf8');
        //$result = mysql_query ('SELECT * FROM wp_posts WHERE post_status="publish" and post_category!=17 and post_category!=18 ORDER BY post_date DESC LIMIT 20', LINK);
        $result = mysql_query('SELECT 

ID
, post_title
, post_content
, post_date
, group_concat(DISTINCT post_category ORDER BY post_category DESC SEPARATOR ", " ) as "categories"

FROM wp_posts, wp_term_relationships,wp_term_taxonomy 
        WHERE wp_posts.post_status = "publish"  
        AND wp_term_relationships.object_id = id
        AND wp_term_taxonomy.taxonomy= "category"
        AND !(wp_term_taxonomy.term_taxonomy_id = 11)
        AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
        GROUP BY ID, post_title, post_content, post_date ORDER BY wp_posts.post_date DESC LIMIT 25', LINK);
        mysql_close(LINK);
        $items = '';
        while($row = @mysql_fetch_array($result))
        {
            $title = UTFayar($row['post_title']);
            $content = UTFayar($row['post_content']);



            $items .= '<item id="'.$row["ID"].'">
                <title><![CDATA['.$title.']]></title>
                <description><![CDATA['. $content .']]></description>
                <pubDate>'.date('D, j M Y H:i:s T', strtotime($row['post_date'])).'</pubDate>
                <category>'.$row['categories'].'</category>
            </item>';
        }
        $items .= '</channel>
                </rss>';

        return $items;
    }  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:00:28+00:00Added an answer on May 26, 2026 at 11:00 am

    The problem is that you need to deal with the categories in some way…. rolling them up and displaying them in a list with commas may be a good way to deal with it.

    mysql has a nice function called “GROUP_CONCAT” http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

    your query would be

        SELECT 
    
        ID
        , post_title
        , post_content
        , post_date
        , group_concat(DISTINCT post_category ORDER BY post_category DESC SEPARATOR ', ' ) as `categories`
    
        FROM wp_posts, wp_term_relationships,wp_term_taxonomy 
                WHERE wp_posts.post_status = "publish"  
                AND wp_term_relationships.object_id = id
                AND wp_term_taxonomy.taxonomy= "category"
                AND !(wp_term_taxonomy.term_taxonomy_id = 11)
                AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
    GROUP BY    ID
        , post_title
        , post_content
        , post_date             
    ORDER BY wp_posts.post_date DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried running a python script: print Hello, World! And I get this error:
I am trying to get a post-commit.bat script running on a Windows Vista Ultimate
Is there an easy way, when running a Ruby script, to get it to
I'm running a cronjob that calls a php script. I get failed to open
Suppose we have a BASH script running some commands in the background. At some
I have to request data for a JS-script from a MySQL database (based upon
My main goal is to get this up and running. My hook gets called
Having some problems with getting some ajax script to work. Using this as the
I am running ruby script/generate scaffold or ruby script/generate model and I know the
I am running a script that animates a plot (simulation of a water flow).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.