Categories
WordPress WordPress Development

Get all category ids in WordPress [Array]

Choose either one of these options to Get all category ids in WordPress as an Array

Get all category ids, Option 1

$output_categories = array();
$categories=get_categories($args);
 foreach($categories as $category) { 
 $output_categories[] = $category->cat_ID;
}

Get all category ids, Option 2

$categories_ids = get_terms(
 array( 'category' ), // Taxonomies
 array( 'fields' => 'ids' ) // Fields
);

Categories
WordPress WordPress Development

Ajax Progress Bar

HTML

<style>
 #progress {
 width: 500px;
 border: 1px solid #aaa;
 height: 15px;
 }
 #progress .bar {
 background-color: #bbd;
 height: 15px;
 }
 </style>
 <div id="progress"></div>

AJAX

<script>

$.ajax({ 

url: ajaxurl.php
success:function(value){
$("#progress").html('<div class="bar" style="width:' + value.percent + '%"></div>');
}
}

</script>

Categories
WordPress WordPress Development

$post Object Output in WordPress

WP_Post Object

WP_Post Object
 (
 [ID] =>
 [post_author] =>
 [post_date] =>
 [post_date_gmt] =>
 [post_content] =>
 [post_title] =>
 [post_excerpt] =>
 [post_status] =>
 [comment_status] =>
 [ping_status] =>
 [post_password] =>
 [post_name] =>
 [to_ping] =>
 [pinged] =>
 [post_modified] =>
 [post_modified_gmt] =>
 [post_content_filtered] =>
 [post_parent] =>
 [guid] =>
 [menu_order] =>
 [post_type] =>
 [post_mime_type] =>
 [comment_count] =>
 [filter] =>
 )

Categories
WordPress WordPress Development

JSON Vs Array in a Database

JSON

  • Faster to encode JSON
  • Takes Less space
  • Human Readable
  • JSON can be used by many other languages

Terms Used : encode, decode

Array

  • Faster to unserialise Array

Terms Used : Serialise, Unserialise

Categories
WordPress WordPress Development

GitIgnore Directory

.gitignore Directory

Example Directory name : uploads

Ignoring ALL folders and files

 # .gitignore
uploads

Result:

# Will Ignore

/uploads # directory
/uploads # file
/example/path/uploads # directory
/example/path/uploads # file

Ignoring only the Root Directory

The correct syntax for that is to put leading and trailing slash:

 # .gitignore
/uploads/

Result:

 # will ignore
/uploads # directory

# will NOT ignore
/uploads              # file
/some/path/uploads    # directory
/another/path/uploads # file

Ignoring only the Root Directory and the Root File

 # .gitignore
/uploads

Result:

# will ignore

/uploads # directory
/uploads # file

Ignoring only Folders and not Files

# .gitignore
uploads/

Result:

# will ignore:
/uploads # directory
/some/path/uploads # directory

# will NOT ignore:
/another/path/uploads # file