How to save metadata in wordpress custom post type

Custom post type are very important in wordpress. Code for save metadata in wordpress custom post type. There are some plugins for creating the post type but I recommend custom code in function.php file.

How to save metadata in wordpress custom post type

I already written about custom post type. If you want to know about custom post type in detail then you can use following articles.

Here in this tutorial I showed How to save the meta data for your custom post type.

add_action( 'add_meta_boxes', 'job_detail_box' );

function job_detail_box() {
add_meta_box(
'job_detail_box',
__( 'job Detail', 'myplugin_textdomain' ),
'job_detail_box_content',
'job',
'normal',
'high'
);
}

function job_detail_box_content( $post ) {
// No need to globalise a post that is an argument on this callback
$meta_p = get_post_meta($post->ID, "jobs_price", true);
$meta_l = get_post_meta($post->ID, "jobs_location", true);

echo '<input type="hidden" name="jobs-nonce" id="jobs-nonce" value="' . wp_create_nonce( 'jobs-nonce' ) . '" />';

?>
<div>
<ul>

<ul>

<ul>
	<li><label>job Price</label>php echo $meta_p; ?>" /></li>
</ul>

</ul>

<ul>

<ul>
	<li><label>job Location</label>php echo $meta_l; ?>" /></li>
</ul>

</ul>

</ul>
</div>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
}

add_action ('save_post', 'save_jobs');

// The save_post hook provides the post id to the return function
function save_jobs( $post_id ){

if ( !wp_verify_nonce( $_POST['jobs-nonce'], 'jobs-nonce' )) {
return $post_id;
}

if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;

update_post_meta($post_id, "jobs_price", $POST['jobs_price'] );
update_post_meta($post_id, "jobs_location", $POST['jobs_location'] );
}

How to save the meta data in wordpress custom post type
How to save the meta data in wordpress custom post type

	

how to display post count of all wordpress tags

In this article, wordpress tutorial, how to display post count of all wordpress tags. In wordpress post we use post tags. For SEO purpose we can show post tags.

how to display post count of all wordpress tags

If we want to show the post count related to wordpress tags.

You can use following code:

<?php
//list all tags that are assigned to posts
$taxonomy = 'post_tag';
$terms = get_terms( $taxonomy, '' );
if ($terms) {
foreach($terms as $term) {
if ($term->count > 0) {
echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
}
}
}
?>
how to display post count of all wordpress tags
how to display post count of all wordpress tags

How to get page id by slug wordpress theme

WordPress tutorial for, How to get page id by slug wordpress theme. First find the page id using page title or page page slug.  we given sample code here.

How to get page id by slug wordpress theme

For post title use following code:

<?php
$page = get_page_by_title( 'About' );
wp_list_pages( 'exclude=' . $page->ID );
?>

For post slug use following code:

 $page = get_page_by_path( 'your-page-slug'
echo $page->ID;

Now List the child page by post slug

if ( $page = get_page_by_path( 'your-page-slug' ) ){
  wp_list_pages( 'orderby=name&depth=1&order=DESC&show_count=0&child_of=' .$page->ID . '&title_li=' );
}

wordpress WP_Query vs query_posts vs get_posts

WordPress tutorial, wordpress WP_Query vs query_posts vs get_posts. There are three ways for fetching data(posts) from wordpress. query_posts  more often than others. But I prefer to use WP_Query(). WP_Query is object base more secure then others.

wordpress WP_Query vs query_posts vs get_posts

wordpress WP_Query vs query_posts vs get_posts
wordpress WP_Query vs query_posts vs get_posts

query_posts() is overly simplistic and problematic way to to modify main query of page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with pagination). Any modern WP code should use more reliable methods, like making use ofpre_get_posts hook, for this purpose. TL;DR don’t use query_posts() ever;

get_posts() is very similar in usage and accepts same arguments (with some nuances, like different defaults), but returns array of posts, doesn’t modify global variables and is safe to use anywhere;

WP_Query class powers both behind the scenes, but you can also create and work with own object of it. Bit more complex, less restrictions, also safe to use anywhere.

The basic difference is that query_posts() is really only for modifying the current Loop. Once you’re done it’s necessary to reset the loop and send it on its merry way. This method is also a little easier to understand, simply because your “query” is basically a URL string that you pass to the function, like so:

query_posts(‘meta_key=color&meta_value=blue’);
On the other hand, wp_query is more of a general purpose tool, and is more like directly writing MySQL queries than query_posts() is. You can also use it anywhere (not just in the Loop) and it doesn’t interfere with any currently running post queries.

enable comments for custom post type

In wordpress we can create the custom post types. Now everybody is using custom post types in wordpress and need comments functionality for custom post types also. Custom post types are very important feature of wordpress. For enabling the comments for custom post type just use the following line.

enable comments for custom post type

'supports' => array('title','editor','author','thumbnail','excerpt','comments')

Following line will add the title, thumbnail, excerpt and comments functionality to your custom post type.

enable comments for custom post type
enable comments for custom post type

For more information use check my following code. I used following code in my functions.php file.

add_action('init', 'wordpress_themes');
 function wordpress_themes() {
 $wp_themes_args = array(
 'label' => __('Wordpress Themes'),
 'singular_label' => __('Wordpress Themes'),
 'public' => true,
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 'rewrite' => true,
  'supports' => array('title','editor','author','thumbnail','excerpt','comments'),
           'taxonomies' => array('category', 'post_tag') // this is IMPORTANT

 );
 register_post_type('wordpress-themes',$wp_themes_args);
 }

compress javascript and css files

Many times we are searching for Javascript and css compression. So here we collected some great web resources which are useful for compress javascript and CSS files.

Use following steps to compress javascript and css files

Few days before i was searching for Jquery JS library compression.

compress javascript and css files
compress javascript and css files

Yes there is compressed version available but i want to make some changes in JS files as per my project requirements.
So i want to compress my JS and CSS files without getting any error.
YUI Compressor 2.4.2. is the very nice tool for that. But i dont want to spend time on how YUI compressor is working.

So here is solution- I got online YUI compressor.
You can use that:
http://refresh-sf.com/yui/
It has very nice options.

http://compressor.ebiene.de/

http://www.cssdrive.com/index.php/main/csscompressor

code syntax highlighter through wordpress plugins

When ever we write some code in post. That code need to visible very easily. Here are some code syntax highlighter through wordpress plugins which will be useful for developers and coders. There are some useful wordpress plugins for highlighting the code in wordpress post.

code syntax highlighter through wordpress plugins
code syntax highlighter through wordpress plugins

 

code syntax highlighter through wordpress plugins

While WordPress.com doesn’t allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing. We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages, like so:

To accomplish the above, just wrap your code in these tags:

 your code here
 

The language parameter controls how the code is syntax highlighted. The following languages are supported:

  • actionscript3
  • bash
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • ruby
  • scala
  • sql
  • vb
  • xml

If the language parameter is not set, it will default to “text” (no syntax highlighting).

Code in between the source code tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

There are some free plugins also helpful for syntax highlighting.  I specially like the SyntaxHighlighter Evolved wordpress plugin. SyntaxHighlighter Evolved allows you to easily post syntax-highlighted code to your site without loosing it’s formatting or making any manual changes.

You can download this plugin form here:

SyntaxHighlighter Evolved

There is another plugin for syntax highlighting which also really nice.

WP-Syntax provides clean syntax highlighting using GeSHi — supporting a wide range of popular languages. It supports highlighting with or without line numbers and maintains formatting while copying snippets of code from the browser.

It avoids conflicts with other 3rd party plugins by running an early pre-filter and a late post-filter that substitutes and pulls the code snippets out first and then pushes them back in with highlighting at the end. The result is source code formatted and highlighted the way you intended.

You can download the this from here:

WP-Syntax