• The plugin generates the following error when using taxonomies:
    Fatal error: Uncaught Error: Cannot use object of type WP_Term as array in /var/www/vhosts/[..]/httpdocs/wp-content/plugins/wp-rest-api-v2-menus/wp-rest-api-v2-menus.php:22

    /**
     * Get all registered menus
     * @return array List of menus with slug and description
     */
    function wp_api_v2_menus_get_all_menus() {
    	$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
    
    	foreach ( $menus as $key => $menu ) {
    		// check if there is acf installed
    		if ( class_exists( 'acf' ) ) {
    			$fields = get_fields( $menu );
    			if ( ! empty( $fields ) ) {
    				$menu[ $key ]->acf = new stdClass();
    
    				foreach ( $fields as $field_key => $item ) {
    					// add all acf custom fields
    					$menus[ $key ]->acf->$field_key = $item;
    				}
    			}
    		}
    	}
    	
    	return apply_filters('wp_api_v2_menus__menus', $menus);
    }

    On lines 22 and 26 the following code is used:
    $menu[ $key ]->acf
    but should be the following, I think:
    $menu->$key->acf

    • This topic was modified 3 years, 8 months ago by dvdm.
  • The topic ‘Fatal error: Uncaught Error: Cannot use object of type WP_Term as array’ is closed to new replies.