The filters are used to customize the default behavior of the plugin and there are many filters hook available in the CPT Ajax load plugin that given below
- cpt_alm_security_wall
- cpt_alm_query_args
- cpt_alm_before_container
- cpt_alm_after_container
- cpt_alm_before_btn
- cpt_alm_after_btn
- cpt_alm_post_not_found
- cpt_alm_shortcode_defaults
cpt_alm_security_wall
The cpt_alm_security_wall plugin can be used to change permission setting to access post types
in the below code only login user can able to see the listing of posts.
function change_permission_user($allow, $id){
// $allow is 0 or 1
// Not permision to allow this post
// $id = 'subscribe_listing'
// in this example only logged in user can see the list of posts.
if(!is_user_logged_in() && $id == 'subscribe_listing')
return 0;
else
return 1;
}
add_filter( 'cpt_alm_security_wall', 'change_permission_user', 10, 2);
cpt_alm_query_args
This filter can modify WP_Query arguments by unique id of the plugin.
Put this code into your functions.php to add taxonomy parameter.
function custom_portfolio_listing($args, $id){
$args['post_type'] = 'portfolio';
$args['tax_query'] = array(
array(
'taxonomy' => 'portfolio-taxonomy',
'field' => 'slug',
'terms' => 'wordpress'
)
);
return $args;
}
add_filter( 'cpt_alm_query_args', 'custom_portfolio_listing', 10, 2);
cpt_alm_before_container
Put your stuff here before start the main container element of the ajax load more
in this example we are adding extra div and this div will e close in next filter.
function add_custom_div($id){
return '<div class="my-custom-div">';
}
add_filter( 'cpt_alm_before_container', 'add_custom_div', 10, 1);
cpt_alm_after_container
Put your stuff here after the main container element of the ajax load more
function add_custom_div_close($id){
return '</div>';
}
add_filter( 'cpt_alm_after_container', 'close_custom_div', 10, 1);
cpt_alm_before_btn
Add specific HTML content before start the Load more button.
in this example we are adding extra div and this div will close in next filter.
function add_custom_div_button($id){
return '<div class="my-custom-button">';
}
add_filter( 'cpt_alm_before_btn', 'add_custom_button_div', 10, 1);
cpt_alm_after_btn
in this example we are closing the div that was added by above filter.
function add_custom_div_button($id){
return '<div class="my-custom-button">';
}
add_filter( 'cpt_alm_after_btn', 'close_custom_button_div', 10, 1);
cpt_alm_post_not_found
Change the default text of the post not found for specific shortcode.
function change_the_post_not_found_text($id){
return 'Not Found';
}
add_filter( 'cpt_alm_post_not_found', 'change_the_post_not_found_text', 10, 1);
cpt_alm_shortcode_defaults
Using this filter you can change the default settings of the shortcode.
Note: Some of the entered wrong value will be breaking the Custom Ajax load more.
function change_default_shortcode($params){
return $params['button_color'] = "#DCDCDC";
}
add_filter( 'cpt_alm_shortcode_defaults', 'change_default_shortcode', 10, 1);