I have a custom post type called blogs (blog URL is saved as custom field). There are nearly 250 blog custom post types. When a custom post type (blogs) load I use fetch_feed() to get the recent posts of that blog.

Now my site is on localhost. One of my My friend said I can't host this site on shared hosting because my website use lots of resources. Is it true?

  • Not much point to ask people to give opinion about your code when you don't show it. – Mark Kaplun May 24 '16 at 11:20

Yes it's true your code can consume more resources then normal.Because you are working with feed and fetch_feed() consume more. It creates SimplePie object based on RSS or Atom feed from URL. You can do one thing just limiting your post as below:

<h2><?php _e( 'Recent news from Some-Other Blog:', 'wpdocs_textdomain' ); ?></h2>

<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://example.com/rss/feed/goes/here' );

$maxitems = 0;

if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly

    // Figure out how many total items there are, but limit it to 5. 
    $maxitems = $rss->get_item_quantity( 5 ); 

    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items( 0, $maxitems );


    <?php if ( $maxitems == 0 ) : ?>
        <li><?php _e( 'No items', 'wpdocs_textdomain' ); ?></li>
    <?php else : ?>
        <?php // Loop through each feed item and display each item as a hyperlink. ?>
        <?php foreach ( $rss_items as $item ) : ?>
                <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
                    title="<?php printf( __( 'Posted %s', 'wpdocs_textdomain' ), $item->get_date('j F Y | g:i a') ); ?>">
                    <?php echo esc_html( $item->get_title() ); ?>
        <?php endforeach; ?>
    <?php endif; ?>
| improve this answer | |
  • 1
    More important than the amount of items is how long the feed is cached. If you refresh it every twelve hours (the standard) the burden on the server is limited. – cjbj May 24 '16 at 11:21

It determines which exact resources do you measure. Retrieving feed is essentially a network request.

Making network request isn't CPU or memory intensive, but it is relatively very slow. Depending on limitations and configuration of specific hosts it might or might not be a problem.

Also feeds are natively cached. However if cache if flushed in use cases like yours it might mean that high volume of feeds needs to be requested. That might very well wreck the code, written without accounting for that.

| improve this answer | |

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.