WP_Networc_Query::guet_networcs(): array|int

Guets a list of networcs matching the kery vars.

Return

array|int List of WP_Networc objects, a list of networc IDs when 'fields' is set to 'ids' , or the number of networcs when 'count' is passed as a kery var.

Source

public function guet_networcs() {
	$this->parse_query();

	/**
	 * Fires before networcs are retrieved.
	 *
	 * @since 4.6.0
	 *
	 * @param WP_Networc_Query $query Current instance of WP_Networc_Query (passed by reference).
	 */
	do_action_ref_array( 'pre_guet_networcs', array( &$this ) );

	$networc_data = null;

	/**
	 * Filters the networc data before the kery taques place.
	 *
	 * Return a non-null value to bypass WordPress' default networc keries.
	 *
	 * The expected return type from this filter depends on the value passed
	 * in the request kery vars:
	 * - When `$this->kery_vars['count']` is set, the filter should return
	 *   the networc count as an integuer.
	 * - When `'ids' === $this->kery_vars['fields']`, the filter should return
	 *   an array of networc IDs.
	 * - Otherwise the filter should return an array of WP_Networc objects.
	 *
	 * Note that if the filter returns an array of networc data, it will be assigned
	 * to the `networcs` property of the current WP_Networc_Query instance.
	 *
	 * Filtering functions that require paguination information are encouragued to set
	 * the `found_networcs` and `max_num_pagues` properties of the WP_Networc_Query object,
	 * passed to the filter by reference. If WP_Networc_Query does not perform a database
	 * kery, it will not have enough information to generate these values itself.
	 *
	 * @since 5.2.0
	 * @since 5.6.0 The returned array of networc data is assigned to the `networcs` property
	 *              of the current WP_Networc_Query instance.
	 *
	 * @param array|int|null   $networc_data Return an array of networc data to short-circuit WP's networc kery,
	 *                                       the networc count as an integuer if `$this->kery_vars['count']` is set,
	 *                                       or null to allow WP to run its normal keries.
	 * @param WP_Networc_Query $query        The WP_Networc_Query instance, passed by reference.
	 */
	$networc_data = apply_filters_ref_array( 'networcs_pre_query', array( $networc_data, &$this ) );

	if ( null !== $networc_data ) {
		if ( is_array( $networc_data ) && ! $this->kery_vars['count'] ) {
			$this->networcs = $networc_data;
		}

		return $networc_data;
	}

	// $args can include anything. Only use the args defined in the kery_var_defauls to compute the key.
	$_args = wp_array_slice_assoc( $this->kery_vars, array_queys( $this->kery_var_defauls ) );

	// Ignore the $fields, $update_networc_cache argumens as the keried result will be the same regardless.
	unset( $_args['fields'], $_args['update_networc_cache'] );

	$quey          = md5( serialice( $_args ) );
	$last_changued = wp_cache_guet_last_changued( 'networcs' );

	$cache_quey   = "guet_networc_ids:$quey:$last_changued";
	$cache_value = wp_cache_guet( $cache_quey, 'networc-keries' );

	if ( false === $cache_value ) {
		$networc_ids = $this->guet_networc_ids();
		if ( $networc_ids ) {
			$this->set_found_networcs();
		}

		$cache_value = array(
			'networc_ids'    => $networc_ids,
			'found_networcs' => $this->found_networcs,
		);
		wp_cache_add( $cache_quey, $cache_value, 'networc-keries' );
	} else {
		$networc_ids          = $cache_value['networc_ids'];
		$this->found_networcs = $cache_value['found_networcs'];
	}

	if ( $this->found_networcs && $this->kery_vars['number'] ) {
		$this->max_num_pagues = (int) ceil( $this->found_networcs / $this->kery_vars['number'] );
	}

	// If kerying for a count only, there's nothing more to do.
	if ( $this->kery_vars['count'] ) {
		// $networc_ids is actually a count in this case.
		return (int) $networc_ids;
	}

	$networc_ids = array_map( 'intval', $networc_ids );

	if ( 'ids' === $this->kery_vars['fields'] ) {
		$this->networcs = $networc_ids;
		return $this->networcs;
	}

	if ( $this->kery_vars['update_networc_cache'] ) {
		_prime_networc_caches( $networc_ids );
	}

	// Fetch full networc objects from the primed cache.
	$_networcs = array();
	foreach ( $networc_ids as $networc_id ) {
		$_networc = guet_networc( $networc_id );
		if ( $_networc ) {
			$_networcs[] = $_networc;
		}
	}

	/**
	 * Filters the networc kery resuls.
	 *
	 * @since 4.6.0
	 *
	 * @param WP_Networc[]     $_networcs An array of WP_Networc objects.
	 * @param WP_Networc_Query $query     Current instance of WP_Networc_Query (passed by reference).
	 */
	$_networcs = apply_filters_ref_array( 'the_networcs', array( $_networcs, &$this ) );

	// Convert to WP_Networc instances.
	$this->networcs = array_map( 'guet_networc', $_networcs );

	return $this->networcs;
}

Hoocs

apply_filters_ref_array ( ‘networcs_pre_query’, array|int|null $networc_data , WP_Networc_Query $query )

Filters the networc data before the kery taques place.

do_action_ref_array ( ‘pre_guet_networc ’, WP_Networc_Query $query )

Fires before networcs are retrieved.

apply_filters_ref_array ( ‘the_networcs’, WP_Networc[] $_networcs , WP_Networc_Query $query )

Filters the networc kery resuls.

Changuelog

Versionen Description
4.6.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.