Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Searching terms by parent produces error if none found #1613

Description

@jasonphillips

When querying terms with the parent parameter set, I'm getting a fatal PHP error (Unsupported operand types) for cases in which it should be an empty array of no results. The line in question is third line here:

$total_terms = wp_count_terms( $this->taxonomy, $prepared_args );
$response->header( 'X-WP-Total', (int) $total_terms );
$max_pages = ceil( $total_terms / $request['per_page'] );

In class-wp-rest-terms-controller.php:
https://github.com/WP-API/WP-API/blob/develop/lib/endpoints/class-wp-rest-terms-controller.php#L105

Since max_pages is set to the result of wp_count_terms, it can sometimes be an empty array instead of an integer, which then causes the division operation to fail. I've found that an explicit cast to int corrects the error.

$max_pages = ceil( (int) $total_terms / $request['per_page'] );

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions