Skip to main content
added 246 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need a non-empty query input in your current code snippet.

Here's a simple test example:

$query = new WP_Query( ['post_type' => 'post' ] );
wp_send_json_success( $query->posts );

but you can check out e.g. wp_ajax_query_attachments() to see how WordPress uses WP_Query in an ajax call.

Also check out the built-in Rest API, it might already have the query you're looking for?

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need a non-empty query input in your current code snippet.

Here's a simple test example:

$query = new WP_Query( ['post_type' => 'post' ] );
wp_send_json_success( $query->posts );

but you can check out e.g. wp_ajax_query_attachments() to see how WordPress uses WP_Query in an ajax call.

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need a non-empty query input in your current code snippet.

Here's a simple test example:

$query = new WP_Query( ['post_type' => 'post' ] );
wp_send_json_success( $query->posts );

but you can check out e.g. wp_ajax_query_attachments() to see how WordPress uses WP_Query in an ajax call.

Also check out the built-in Rest API, it might already have the query you're looking for?

Post Undeleted by birgire
added 246 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need a non-empty query input arguments in your current code snippet.

Here's a simple test example:

$query = new WP_Query( ['post_type' => 'post' ] );
wp_send_json_success( $query->posts );

but you can check out e.g. wp_ajax_query_attachments() to see how WordPress uses WP_Query in an ajax call.

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need non-empty input arguments in your current code snippet.

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need a non-empty query input in your current code snippet.

Here's a simple test example:

$query = new WP_Query( ['post_type' => 'post' ] );
wp_send_json_success( $query->posts );

but you can check out e.g. wp_ajax_query_attachments() to see how WordPress uses WP_Query in an ajax call.

Post Deleted by birgire
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Note that the constructor of WP_Query is:

public function __construct( $query = '' ) {
    if ( ! empty( $query ) ) {
        $this->query( $query );
    }
}

so you need non-empty input arguments in your current code snippet.