WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay Now I'm editing old problem because its done but now i've new problem I've knowledge of mysql queries but not wordpress queries I'm doing this with mysql queries and its working well but server is going damn slow i know i'm running about 30 query per page load so is there any way to do it easily with help of wordpress queries or something else ???

 <?php $rss = fetch_feed('http://example.com/feed');
    if (!is_wp_error( $rss ) ) :
        $maxitems = $rss->get_item_quantity(10); 
        $rss_items = $rss->get_items(0, $maxitems); 
     if ($maxitems == 0) ;
        foreach ( $rss_items as $item ) :
        $result=mysql_query("SELECT post_title FROM wp_posts WHERE post_title='".$pt."'");
        echo "hello";
        mysql_query("UPDATE wp_posts SET post_title='".$pt."',post_content='".$pc."' WHERE post_title='".$pt."'");
        echo "hi";
        mysql_query("INSERT INTO wp_posts (post_title,post_content) VALUES ('".$pt."','".$pc."')");
        endforeach; ?>
share|improve this question
up vote 1 down vote accepted

You can do this on background using some ajax on page load, here is an untested example to show the idea.

jQuery(function() {

function is_ajax()
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

function add_rewrite_rules($wp_rewrite)
    $new_rules = array
        'remote' => 'index.php?remote=true'

    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

function add_query_vars($vars)
    array_push($vars, 'remote');
    return $vars;

function remote_feed()
    if (($var = get_query_var('remote')) and is_ajax())
        // get remote feed and insert/update posts

add_action('generate_rewrite_rules', 'add_rewrite_rules');
add_action('template_redirect', 'remote_feed');
share|improve this answer

Creation of new post should be done with wp_insert_post() functions.

Also such tasks as fetching remote resources and inserting in database on every page load usually make little sense. What is the point of requesting and inserting same data over and over again?


Updates will not be much different from inserts for performance. Overwriting everything from feed each time is just horribly inefficient.

There are couple of optimizations to process that would reduce load:

  • run code less often and decouple it from page loads, WP Cron functionality is suitable for this
  • only insert new posts, this means you would need to identify posts already present in database by some criteria (depends on your source data)
  • if you still want to update posts already present, try to determine first if they have been actually changed, for example by comparing of dates
share|improve this answer
wel i want if in that feed any new post is comes so only that post can inserted and others updated but that makes too much load in server – Mohit Bumb Oct 9 '11 at 21:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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