News

Ignore sort apply for certain query on Post Types Order

This replaced the deprecated filter pto/posts_orderby

The free WordPress plugin Post Types Order is already a “must have” code on any website. Control any post sorting through a nice and easy to use interface.

When Autosort is ON, the sorting is applied to all queries that match the post type. It can be forced by either using the ignore_custom_sort argument within the query , or by using a filter pto/posts_orderby/ignore which can be placed within any code, preferable on theme functions.php

Example
The following code ignore the sort apply for any query which include ‘reports’ post type

	add_filter('pto/posts_orderby/ignore', 'theme_pto_posts_orderby', 10, 3);
    function theme_pto_posts_orderby($ignore, $orderBy, $query)
       {
           if( (! is_array($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'reports') || 
                   (is_array($query->query_vars)   &&  in_array('reports', $query->query_vars)))
                   $ignore = TRUE;
           
           
           return $ignore;
       }

Apply post type Archive order for all taxonomies / categories

The Advanced Post Types Order plugin is very flexible in functionality. In certain situations, individual sort for each taxonomy terms (categories) is not required, but instead Archive order is needed to apply on all other sections.

The following example return the archive order for any query that match the post type array. The apto_query_match_sort_id filter is being used:
(more…)

Hide Sort Settings interface for certain administrator role users

The Sort Settings interface is available by default only to administrator role users. There are situations when sort settings need to be available only for certain users. The apto/wp-admin/reorder-interface/view-settings-capability filter help on that matter.

The following example hide the sort settings interface if logged-in user is not ID 1 or 2 or 3. This can be extended to check against username, user meta data etc. If not match it should return a capability that current user does not support.

add_filter('apto/wp-admin/reorder-interface/view-settings-capability', 'view_settings_capability');
    function  view_settings_capability($capability)
        {
            $user_ID = get_current_user_id();
            
            if(!in_array($user_ID, array(1, 2, 3)))
                $capability =   '_sort_capability_';
            
            return $capability;   
        }

Automatic Sort for all new future created categories

Sorting post types within Taxonomies Terms become an easy task through Advanced Post Types Order plugin. Further more the Automatic Sort functionality put the code on work and make the sort for you per predefined criteria https://www.nsp-code.com/advanced-post-types-order-description-and-usage/manual-automatic-sorting-type-usage/

The Automatic Sort is an efficient way to improve site management productivity by reduce redundant sort actions. It takes arguments for a particular taxonomy terms and auto-sort any objects inside (previously created or future ones) by that criteria.

What if Automatic Sort is needed to be created automatically once a new taxonomy term (like categories) has been created? This is an easy task, using the Advanced Post Types Order plugin API’s.
(more…)

Autosort a Category by posts Featured Image Title

The Automatic Order functionality along with Custom Function it’s a very powerful tool to customize the sort of a give area by very specific criteria. As specified at https://www.nsp-code.com/applying-automatic-order-for-a-sort-through-a-user-function-callback/ the filter return a list of all posts within the section / query on which different operations can apply.
(more…)

Pagination on AJAX Sort List Update

For very large list, it can be a challenge to save an order list. Something this can take a while, on certain hosts it can be stopped from execution returning an 500 server error. The main cause for this is a php environment variable called Maximum Execution Time. This is generally set for 30 seconds.
When Pagination is set for Advanced Post Types Order plugin, the timeouts are no longer a problem, the sort list save job is split into small chunks to allow server to process the data.

Pagination on AJAX Sort List Update - progress

Additionally, a progress data is being show, the current chunk page out of total jobs.

Applying multiple order criteria for Automatic Order through Fallback functionality

The Advanced Post Types Order plugin include an easy way to automatically sort objects of a list (e.g. post type archive, category list, mix of post types and taxonomies terms etc) through a powerful functionality called Automatic Order. This will auto update sort for objects on front site.

advanced-post-types-order-automatic-sort-interface-example

(more…)

Applying a different capability for Administrator when using Advanced Post Types Order

By default the Advanced Post Types Order plugin use the ‘switch_themes’ capability for Administrator role. There are situations when this capability is not available or is been removed or relocated for another role, meaning administrators are not able to see or change a sort.

The following code show how to change the ‘switch_themes’ to ‘activate_plugins’ capability.


//capability to see the re-order menu interface
add_filter('apto_reorder_capability', 'custom_apto_reorder_capability');

//capability to allow a new sort to be created
add_filter('apto/wp-admin/reorder-interface/view-settings-capability', 'custom_apto_reorder_capability');

//individual tabs view. This overwrite the default capability set through sort setting
add_filter('apto/wp-admin/reorder-interface/sort-view-required-capability', 'custom_apto_reorder_capability');
    
function custom_apto_reorder_capability($capability)
    {
        $capability =   'activate_plugins';
           
        return $capability;
    }

Creating custom format for licence keys on WooCommerce Software License plugin

To create a custom licence key, the woo_sl/generate_license_key filter can be used. This send along 4 arguments:

  • $license_key
  • $order_id
  • $order_item_id
  • $license_group_id

(more…)

Use Pre-Generated Licence Keys with WooCommerce Software License

Starting version 1.2 (6-October-2015) the WooCommerce Software License plugin got a new enhancement, the ability to use existing keys (own admin keys) along the plugin code. If you are a re-seller this become the great tool for selling keys and software. All existing functionality like allowed client keys, instances per key etc, can still apply. Also multiple Licensing groups can be created allowing mix of pre-generated with automated keys to be bundled toughener.

(more…)