0

I tried to create a class that extends WP_Query, but I got this error: Allowed memory size of 1073741824 bytes exhausted I've increased the memory size in wp-config.php but that doesn't affect.

Here is my code:

class WPO_Query extends WP_Query {
    var $post_type = 'wp_order';

    public function __construct( $args = array() ) {
    }

    public function query( $data = array() ) {
        return parent::__construct( $data );
    }
}

and

$queries = new WPO_Query();
$orders = $queries->query( array( 'some' => 'data' ) );

But I won't get a error, when I use parent::__construct inside class __construct. I hope you guys answer me instead vote me down.

4
  • What do you actually have instead of "some => data" and what happens if you use wp_query instead of your class? Aug 12, 2014 at 15:39
  • 1
    Put parent::__construct( $args ); in the __construct (no return) and return parent::__query( $data ); in the query. Presumably you want to always set the post_type? Then put $args['post_type'] = $this->post_type; in the __construct before calling the parent.
    – bonger
    Aug 12, 2014 at 15:47
  • @MarkKaplun I set required info.
    – Ehsaan
    Aug 12, 2014 at 15:51
  • @bonger Thanks a lot, worked, but query instead of __query. Write it as an answer.
    – Ehsaan
    Aug 12, 2014 at 15:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.