Managing WordPress Revisions

wordpress-revisions

WordPress revisions are kind of automatically taken backups of your wordpress post or page. This feature is very much useful if you lost your page content by mistake, or you couldn’t save your changes due to sudden restart etc.

wordpress-revisionsRevisions are automatically store for all the post types ( page, post, media and all the custom post types ). But by default this is visible only on default wordpress post types (page, post, medea etc). If you are defining a new post type, you will explicitly have to define the support of revisions.

Enable revisions for custom post types

Revisions are not enabled for custom post types by default. Hence enabling revisions should define for each custom post type. To do that ‘revisions’ should be added to ‘supports’ array of the custom post type args.

'supports' => array( 'title', 'editor', 'revisions' );

Limiting wordpress revisions

WordPress itself stores up-to 25 revisions per each post by default. Old revisions will be deleted automatically and new revisions will be stored. But we can define how many revisions we need wordpress to store for us. It can be done by adding bellow code on wp-config.php

define('WP_POST_REVISIONS', 3);

Comparing Revisions

To compare any reviews, just click on “Brows” link showed in the above screenshot and you will see a comparison. Two change which revision to be compared, you can slide the bar at the top. Newly added contents are marked in green and deleted content marked in red. See the picture bellow

revision-comparing

Jquery autocomplete passing additional parameters

Sometimes you may need to use jquery autocomplete function passing additional parameters. I had a such requirement  in one of my recent project. I searched here and there to find the right solution and it was quite hard. So, I thought to share what I did to get it success here.

Why additional parameters should pass to autocomplete?

Lets think of a situation where searching a certain term in a field of database table. You may need to use extra condition which relevant with a client side variable like input value of a form. In such case, that particular input value is to be passed to the script processing search functionality in addition to the search term. This is where you need a functionality to pass additional parameter to jquery autocomplete function.

This is the syntax for pass additional parameters to jquery autocomplete.

$("selector").autocomplete({
    source: function(request, response) {
        $.getJSON(url, { key1:value1, key2:value2 }, response);
    },
    minLength: 2
 });

If this syntax is used, the search term should pass as one parameter. And any number of additional parameters can be passed. Here is one practical example where I passed additional parameters to jquery autocomplete.

$("#account-number").autocomplete({
    source: function(request, response) {
        $.getJSON(SITE_NAME + '/bankaccount/getaccounts/', { bank_code: $('#bank-code').val(), term : request.term }, response);
    },
    minLength: 2
});

Think you found something useful reading this article. Thank you for reading