0

I have a Parent theme with the following function:

function getTourOffers($tourId) {

        global $aitThemeOptions;


        $params = array(
            'post_type'         => 'ait-dir-item-offer',
            'nopaging'          =>  true,
            'post_status'       => 'publish',
            'meta_query'        => array(
                array(
                    'key' => 'ait_item_id',
                    'value' => $tourId,
                    'compare' => '='
                )
            )
        );
        $query = new WP_Query($params);
        $currency = (isset($aitThemeOptions->directory->currency)) ? $aitThemeOptions->directory->currency : '';
        $dateFormat = get_option( 'date_format', 'F j, Y' );
        foreach ($query->posts as $offer) {
            $offer->options = get_post_meta( $offer->ID, '_ait-dir-item-offer', true );
            $offer->from = date($dateFormat,strtotime($offer->options['from']));
            $offer->to = date($dateFormat,strtotime($offer->options['to']));
            $offer->price = $currency . ' ' . $offer->options['price'];
            $offer->capacity = (isset($offer->options['capacity'])) ? intval($offer->options['capacity']) : 0;
        }
        return $query->posts;

    }

Is it possible to change the parameters of the function in the Child theme? I would like the function to be like this in the Child theme:

function getTourOffers($tourId) {

    global $aitThemeOptions;


    $params = array(
        'post_type'         => 'ait-dir-item-offer',
        'nopaging'          =>  true,
        'post_status'       => 'publish',
        'order'     => 'ASC',
        'meta_key' => 'ait_date_from',
        'orderby'   => 'meta_value',
        'meta_query'        => array(
            array(
                'key' => 'ait_item_id',
                'value' => $tourId,
                'compare' => '='
            )
        )
    );
    $query = new WP_Query($params);
    $currency = (isset($aitThemeOptions->directory->currency)) ? $aitThemeOptions->directory->currency : '';
    $dateFormat = get_option( 'date_format', 'F j, Y' );
    foreach ($query->posts as $offer) {
        $offer->options = get_post_meta( $offer->ID, '_ait-dir-item-offer', true );
        $offer->from = date($dateFormat,strtotime($offer->options['from']));
        $offer->to = date($dateFormat,strtotime($offer->options['to']));
        $offer->price = $currency . ' ' . $offer->options['price'];
        $offer->capacity = (isset($offer->options['capacity'])) ? intval($offer->options['capacity']) : 0;
    }
    return $query->posts;

}

Also, does it matter that the function in question is not in the functions.php file but located in a functions folder along with several other files containing functions?

  • 1
    With the code you posted it seems that the function can not be overrided on child themes. You should ask to theme developer to allow it. – cybmeta Jan 9 '15 at 9:57
  • 1
    It this situation, it is better to create a new function like in your second block of code. Just change the name and then update the affected template files in your child theme – Pieter Goosen Jan 9 '15 at 10:01
  • 2
    @cybmeta Unfortunately the theme developers will not allow the function to be overridden in the child theme and will not assist me with recreating it in the child theme....@PieterGoosen You're probably correct but the function is referenced a lot throughout this complex theme and I think it would be too difficult for me to update all the necessary files in the child theme. To add further complications the theme also uses a custom templating engine that I'm not familiar with. Probably I will end up editing the Parent theme. Thank you for your assistance anyways. – Ciaran Gaffey Jan 9 '15 at 10:27
  • If you are going to modify the parent theme, be sure to keep a backup of that function as updates will override this custom function. – Pieter Goosen Jan 9 '15 at 10:31

Your Answer

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

Browse other questions tagged or ask your own question.