I try to get more than 3 feed from other web site and show it in my site like :

function fw_shortcode( $atts ) {

    global $wpdb, $feedtable;
    $result=mysql_query("SELECT * FROM " . $feedtable . " ORDER BY RAND() LIMIT 3");

    while( $row=mysql_fetch_array($result) ) {  
        $rss = fetch_feed($row["weburl"]);
        if (!is_wp_error( $rss ) ) : 

            $maxitems = $rss->get_item_quantity(1);
            $rss_items = $rss->get_items(0, $maxitems);

            foreach ( $rss_items as $item ) :

                $code .= '  <article class="col-md-4 col-sm-6 col-xs-12" itemscope="" itemtype="http://schema.org/BlogPosting">
                                <div class="vendoritem">';
                $code .= '          <a href="' . esc_url( $item->get_permalink() ) . '"  target=' . "_blank".'>';
                $code .= '              <img width="300" height="225" src="' . get_first_image_url($item->get_description()) . '" class="img-responsive relat wp-post-image" style="background-color:#3498db;">';
                $code .= '          </a>
                                    <div class="vendoritem__details">
                                        <a href="' . esc_url( $item->get_permalink() ) . '" class="vendoritem__title" target=' . "_blank" . '>' . esc_html( $item->get_title() ) . '</a>


        /* End Loop */

    $code .= '</div>';

    return $code;



My problem is i need to shoe only random 3 feed from table. but some time show me 2 feed, Why !!, and if any feed not work, how can get other feed from DB

  • 2
    I can see that you've asked 17 questions, but they are all still open. Please update the status of those questions and close any of them if they have been solved (see e.g. What should I do when someone answers my question?) Note that you can also post an answer yourself and accept it to close it. I'm sure you got great solutions to some of your questions, that could benefit other readers as well. Thanks. – birgire Sep 20 '15 at 10:48

It's difficult to answer this, but here are some suggestions:

  • Make sure your feeds are valid, e.g. here.
  • In the case of is_wp_error( $rss ) giving true, you can check the corresponding error message with $rss->get_error_message().
  • Develop with WP_DEBUG activated.
  • Don't use mysql_query(), it's deprecated since PHP 5.5.
  • Use the $wpdb object to fetch data from your custom table.
  • Escape/prepare your SQL if it uses any user input, to avoid SQL injections.
  • Indent your code to make it more readable.
  • Remove the wp_reset_query() line, it's doing nothing after the return.

Then update your question accordingly with more info. Thanks.

  • all feed are valid and there are no error and my sql not have any sql-injection – Zamalek Man Sep 20 '15 at 11:20
  • Is that the case when only 2 items show up, instead of 3? You could use an else to print out the possible error messages. @ZamalekMan – birgire Sep 20 '15 at 11:46
  • if its show me 2 item. i need code to get one item to complete 3 item – Zamalek Man Sep 21 '15 at 16:50
  • You could fetch e.g. 6 urls instead of 3 and if a feed fails, you can try another one. Another approach would be to do this recursively. @ZamalekMan – birgire Sep 22 '15 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.