WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Just a quick question. I have a form that calculates values based on user entry. The information is then passed via ajax to a php file for calculation returning the results. The problem is that that PHP file needs to reference the header as it needs to use the get_posts function to receive the string and collapse it into an array. Problem is that that bulks up the file massively and courses functions to execute in the header that we do not want as then the whole damn header arses up the ajax load and we get a blank screen.

So is there a way or a place to put this file whereby it can get_posts without having the bulky header load as well. Bit of code here if you are interested.

if (is_page('main-functions')) {

$str = dataSting;

$totalprice_posts = get_posts('post_type=services&numberposts=-1');
$totalprice_array = array();
foreach ($totalprice_posts as $post) {
    $productprice = $_POST['price'.$post->ID];
    $productprice = $_POST['quant'.$post->ID];
    $totalproductprice = ($productprice * $productquantity);
    array_push($totalprice_array, $totalproductprice);
implode(',', $totalprice_array);
$totalprice = array_sum($totalprice_array);
 echo $totalprice;



Any ideas,


share|improve this question

Hmm...i might be getting you wrong, but do you know that WP comes with an AJAX callback framework that helps you with this, making calling your own callback file unneccessary?

share|improve this answer
I did not know that. But how would I get it to do what I want. My custom PHP file calculates the values sent to it. – Robin I Knight Mar 1 '11 at 13:32
See the link in the above answer, there's an example right there. – t31os Mar 1 '11 at 13:53
@Robin I Knight: Exactly, see the linked answer, google for more if needed, look at the WP code, if necessary. – wyrfel Mar 1 '11 at 18:40

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.