Skip to content

Commit

Permalink
Merge pull request #86 from ryanwelcher/feature/remove-pagniation
Browse files Browse the repository at this point in the history
Add control to disable pagnination
  • Loading branch information
ryanwelcher authored Oct 9, 2024
2 parents de91b57 + 5e17ad7 commit 115fa12
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
6 changes: 4 additions & 2 deletions includes/Query_Params_Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Query_Params_Generator {
use Traits\Include_Posts;
use Traits\Meta_Query;
use Traits\Date_Query;
use Traits\Disable_Pagination;


/**
Expand All @@ -28,6 +29,7 @@ class Query_Params_Generator {
'include_posts',
'meta_query',
'date_query',
'disable_pagination',
);

/**
Expand Down Expand Up @@ -58,8 +60,8 @@ class Query_Params_Generator {
* @param array $custom_params Custom values from AQL.
*/
public function __construct( $default_params, $custom_params ) {
$this->default_params = is_array( $default_params ) ? $default_params : [];
$this->custom_params = is_array( $custom_params ) ? $custom_params : [];
$this->default_params = is_array( $default_params ) ? $default_params : array();
$this->custom_params = is_array( $custom_params ) ? $custom_params : array();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions includes/Traits/Disable_Pagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Trait for managing pagination.
*/

namespace AdvancedQueryLoop\Traits;

trait Disable_Pagination {

public function process_disable_pagination() {
$this->custom_args['no_found_rows'] = $this->get_custom_param( 'disable_pagination' );
}
}
5 changes: 4 additions & 1 deletion includes/Traits/Include_Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function process_include_posts() {
* @return array
*/
protected function get_include_ids( $include_posts ) {
return array_column( $include_posts, 'id' );
if ( is_array( $include_posts ) ) {
return array_column( $include_posts, 'id' );
}
return array();
}
}
29 changes: 29 additions & 0 deletions src/components/pagination-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* WordPress dependencies
*/
import { ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export const PaginationToggle = ( { attributes, setAttributes } ) => {
const { query: { disable_pagination: disablePagination } = {} } =
attributes;

return (
<ToggleControl
label={ __( 'Disable pagination', 'advanced-query-loop' ) }
help={ __(
'Disabling pagination will not show any pagination controls on the front end. It can also provide a performance improvement for complicated queries.',
'advanced-query-loop'
) }
checked={ !! disablePagination }
onChange={ () => {
setAttributes( {
query: {
...attributes.query,
disable_pagination: ! disablePagination,
},
} );
} }
/>
);
};
2 changes: 2 additions & 0 deletions src/variations/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { MultiplePostSelect } from '../components/multiple-post-select';
import { PostOrderControls } from '../components/post-order-controls';
import { PostExcludeControls } from '../components/post-exclude-controls';
import { PostIncludeControls } from '../components/post-include-controls';
import { PaginationToggle } from '../components/pagination-toggle';

/**
* Determines if the active variation is this one
Expand Down Expand Up @@ -56,6 +57,7 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {
'advanced-query-loop'
) }
>
<PaginationToggle { ...props } />
<MultiplePostSelect { ...props } />
<PostCountControls { ...props } />
<PostOffsetControls { ...props } />
Expand Down

0 comments on commit 115fa12

Please sign in to comment.