The get_query_pagination_arrow() WordPress PHP function is a helper function that returns the proper pagination arrow HTML for QueryPaginationNext and QueryPaginationPrevious blocks based on the provided paginationArrow from QueryPagination context.
Usage
get_query_pagination_arrow( $block, $is_next );
Parameters
$block (WP_Block): The block instance, required.$is_next (bool): A flag for handling next/previous blocks, required.
More information
See WordPress Developer Resources: get_query_pagination_arrow
Examples
Displaying a basic pagination arrow
In this example, we use get_query_pagination_arrow() to display a basic pagination arrow.
// Define the block instance $block = new WP_Block( array( 'blockName' => 'core/query-pagination-next' ) ); // Get the next pagination arrow $next_arrow = get_query_pagination_arrow( $block, true ); echo $next_arrow; // Output: ">"
Customizing the pagination arrow
In this example, we customize the pagination arrow using the block’s context.
// Define the block instance with custom arrow
$block = new WP_Block(
array(
'blockName' => 'core/query-pagination-next',
'context' => array( 'paginationArrow' => '>>' ),
)
);
// Get the next pagination arrow
$next_arrow = get_query_pagination_arrow( $block, true );
echo $next_arrow; // Output: ">>"
Using the function in a Query Loop
In this example, we use get_query_pagination_arrow() within a Query Loop to display the next and previous pagination arrows.
// Define the block instances $next_block = new WP_Block( array( 'blockName' => 'core/query-pagination-next' ) ); $prev_block = new WP_Block( array( 'blockName' => 'core/query-pagination-previous' ) ); // Get the next and previous pagination arrows $next_arrow = get_query_pagination_arrow( $next_block, true ); $prev_arrow = get_query_pagination_arrow( $prev_block, false ); echo $prev_arrow . ' | ' . $next_arrow; // Output: "< | >"
Handling RTL languages
In this example, we handle Right-to-Left (RTL) languages by reversing the next and previous pagination arrows.
// Define the block instances
$next_block = new WP_Block( array( 'blockName' => 'core/query-pagination-next' ) );
$prev_block = new WP_Block( array( 'blockName' => 'core/query-pagination-previous' ) );
// Get the next and previous pagination arrows
$next_arrow = get_query_pagination_arrow( $next_block, true );
$prev_arrow = get_query_pagination_arrow( $prev_block, false );
// Check if the current language is RTL
if ( is_rtl() ) {
$temp_arrow = $next_arrow;
$next_arrow = $prev_arrow;
$prev_arrow = $temp_arrow;
}
echo $prev_arrow . ' | ' . $next_arrow; // Output: "< | >" (or "> | <" for RTL languages)