Skip to main content

Generic_Ajax_Query

This class is used for the node-archive block. Can be extended for custom ajax query blocks.

Overview​

Methods​

NameReturn TypeSummary/Returns
extra_args()Add extra arguments to the query.
get()Get an allowlisted protected property value.
prepare()Prepare parameters before building the query arguments.
query_args()Setup query arguments for the query.
register()Handle the registration of the AJAX actions.

Class Methods​

extra_args()​

Add extra arguments to the query.

Can be extended by running the parent method from within the child class.

extra_args( ?array $extra_args )

NameTypeDescription
$extra_argsnull or arrayextra arguments for the query.

get()​

Get an allowlisted protected property value.

You can use this method to retrieve the value of certain protected properties of the class. Mainly used for accessing private properties in filters and actions.

Allowed properties:

  • posts_total
  • posts_loaded
  • post_type
  • taxonomy
  • terms
  • terms_changed
  • posts_per_page
  • query_args
  • card_type
  • show_excerpt
  • card_classes
  • columns
  • current_action

get( string $property )

NameTypeDescription
$propertystringProperty name to retrieve.

PHP

add_filter('wp-lemon/filter/ajax-query/load_posts/context', function ($context, $instance) {
$context['posts_left'] = max(0, (int) $instance->get('posts_total') - (int) $instance->get('posts_loaded'));
return $context;
}, 10, 2);

prepare()​

Prepare parameters before building the query arguments.

Can be extended by running the parent method from within the child class.


query_args()​

Setup query arguments for the query.

Can be extended or overwritten by running the parent method from within the child class.


register()​

Handle the registration of the AJAX actions.

Can be extended for custom AJAX queries.