Tag Archives: post

main post under sub posts

functions.php


function trove_custom_init() {
$labels = array(
'name' => __('Treasure Trove','themename'),
'singular_name' => __('trove','themename'),
'add_new' => __('Add New','themename'),
'add_new_item' => __('Add New Treasure Trove','themename'),
'edit_item' => __('Edit Treasure Trove','themename'),
'new_item' => __('New Treasure Trove','themename'),
'all_items' => __('All Treasure Trove','themename'),
'view_item' => __('View Treasure Trove','themename'),
'search_items' => __('Search Treasure Trove','themename'),
'not_found' => __('No Treasure Trove found','themename'),
'not_found_in_trash' => __('No Treasure Trove found in Trash','themename'),
'parent_item_colon' => "",
'menu_name' => __('Treasure Trove','themename')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'trove' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail','page-attributes'),
);
register_post_type( 'trove', $args );
}
add_action( 'init', 'trove_custom_init' );

page-template.php


<div class="blog-details single">
<?php
global $post;
$troveargs = array(
'paged' => $paged,
'post_type' => 'trove',
'post_status' => 'publish',
'order' => 'ASC',
'post_parent' => 0
);
$trove_query = new WP_Query($troveargs);

while ( $trove_query->have_posts() ) : $trove_query->the_post();
//if ($post->post_parent == 0) {
?>
<div class="col-md-12 no-padding trovebox">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_content(); ?>
</p>
</div>
<?php
/* Start Second Loop of sub procuct listed under main product */
$troveargs_sub = array(
'paged' => $paged,
'post_type' => 'trove',
'post_status' => 'publish',
'order' => 'ASC',
'post_parent' => $post->ID
);
$trove_query_sub = new WP_Query($troveargs_sub);
while ( $trove_query_sub->have_posts() ) : $trove_query_sub->the_post();
//echo wp_get_post_parent_id( $post_ID );
?>
<div class="col-md-12 no-padding trovebox">
<h4>
<?php the_title(); ?>
</h4>
</div>
<?php endwhile;
/* End Second Loop*/
?>
<?php endwhile; ?>
</div>

Renaming “Post” to Something Else

Refrence:
http://stackoverflow.com/questions/26145878/renaming-post-to-something-else

functions.php


// Function to change "posts" to "news" in the admin side menu
function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = 'News Articles';
$submenu['edit.php'][5][0] = 'News Articles';
$submenu['edit.php'][10][0] = 'Add News Article';
$submenu['edit.php'][16][0] = 'Tags';
echo '';
}
add_action( 'admin_menu', 'change_post_menu_label' );
// Function to change post object labels to "news"
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'News Articles';
$labels->singular_name = 'News Article';
$labels->add_new = 'Add News Article';
$labels->add_new_item = 'Add News Article';
$labels->edit_item = 'Edit News Article';
$labels->new_item = 'News Article';
$labels->view_item = 'View News Article';
$labels->search_items = 'Search News Articles';
$labels->not_found = 'No News Articles found';
$labels->not_found_in_trash = 'No News Articles found in Trash';
}
add_action( 'init', 'change_post_object_label' );

Create and display custom post type with Texonomy, Metabox and Tag

function.php


/***** Adding custom post type - Portfolios *****/
function portfolios_custom_init() {
$labels = array(
'name' => __('Portfolios','themename'),
'singular_name' => __('portfolios','themename'),
'add_new' => __('Add New','themename'),
'add_new_item' => __('Add New Portfolio','themename'),
'edit_item' => __('Edit Portfolio','themename'),
'new_item' => __('New Portfolio','themename'),
'all_items' => __('All Portfolios','themename'),
'view_item' => __('View Portfolios','themename'),
'search_items' => __('Search Portfolio','themename'),
'not_found' => __('No Portfolios found','themename'),
'not_found_in_trash' => __('No Portfolios found in Trash','themename'),
'parent_item_colon' => '',
'menu_name' => __('Portfolios','themename')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'portfolios' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail')

);
register_post_type( 'portfolios', $args );
register_taxonomy("portfolio-categories",
array("portfolios"),
array("hierarchical" => true,
'show_admin_column'   => true,
"label" => "Portfolio Categories",
"singular_label" => "Portfolio Categories",
"rewrite" => array( 'slug' => 'portfolio_category' ,

)));

register_taxonomy("portfolio-tag",
array("portfolios"),
array("hierarchical" => false,
'show_admin_column'   => true,
"label" => "Portfolio Tag",
"singular_label" => "Portfolio tag",
"rewrite" => array( 'slug' => 'portfolio_tag' ,

)));

}
add_action( 'init', 'portfolios_custom_init' );

/*****  Custom Meta Box - portfolios *****/

add_action( 'add_meta_boxes', 'meta_box_portfolio' );
function meta_box_portfolio()
{
add_meta_box( 'meta_box_portfolio_id', 'Enter Portfolio info', 'portfolio_website_info', 'portfolios', 'normal', 'high' );
}
function portfolio_website_info( $post )
{
$values = get_post_custom( $post->ID );
$portfolio_url = isset( $values['portfolio_url'] ) ? esc_attr( $values['portfolio_url'][0] ) : '';
$portfolio_text = isset( $values['portfolio_text'] ) ? esc_attr( $values['portfolio_text'][0] ) : '';
$portfolio_image = isset( $values['portfolio_image'] ) ? esc_attr( $values['portfolio_image'][0] ) : '';

wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>Portfolio URL</p>
<input type="text" name="portfolio_url" value="<?php echo esc_url( $portfolio_url ); ?>" class="widefat" placeholder="Portfolio Url" />
<p>Portfolio Text</p>
<input type="text" name="portfolio_text" value="<?php echo esc_attr( $portfolio_text ); ?>" class="widefat" placeholder="Portfolio Text" />
<p>Portfolio Image</p>
<input id=""  type="text" class=" mytheme_media_url upload" name="portfolio_image" value="<?php echo esc_attr( $portfolio_image ); ?>" placeholder="No file chosen"  />
<?php if(!empty($instance['image'])) { ?><img src="<?php echo $instance['image']; ?>"  /><?php } ?>
<input id="mytheme_image_uploader"  class="button mytheme_media_upload" type="button" value="Upload" />

<?php
}
add_action( 'save_post', 'portfolio_meta_box_save' );
function portfolio_meta_box_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( isset( $_POST['portfolio_url'] ) ) update_post_meta( $post_id, 'portfolio_url', esc_url( $_POST['portfolio_url'] ) );
if( isset( $_POST['portfolio_text'] ) ) update_post_meta( $post_id, 'portfolio_text', esc_attr( $_POST['portfolio_text'] ) );
if( isset( $_POST['portfolio_image'] ) ) update_post_meta( $post_id, 'portfolio_image', esc_attr( $_POST['portfolio_image'] ) );
}
/*** end ***/

Enque media-uploader-post.js.js file for upload image by metabox.


wp_enqueue_script('media-uploader', get_template_directory_uri() . '/js/media-uploader-post.js', array('jquery'));

Display in page template


<div class="row">
<?php
$legal_portfolio_args = array(
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'ASC',
'post_type' => 'portfolios',
'post_status' => 'publish'
);
$legal_portfolio = new WP_Query( $legal_portfolio_args );
while ( $legal_portfolio->have_posts() ) { $legal_portfolio->the_post();
?>
<div class="col-md-6 col-sm-6 attorneys">
<div class="our-section-box">
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" target="_blank">
<div class="col-md-12 no-padding our-box-left">
<?php the_post_thumbnail( 'legal-ourteam-thumbnail-image', array( 'alt' => get_the_title(), 'class' => 'img-responsive') ); ?>
</div>
</a>
<?php } ?>
<div class="col-md-12 our-box-right">
<h4><?php the_title(); ?></h4>
<?php the_content(); ?>
<?php
echo 'URL: '.  get_post_meta( get_the_ID(), 'portfolio_url', true );
echo '<br>text: '. get_post_meta( get_the_ID(), 'portfolio_text', true );
echo '<br>Image: '. get_post_meta( get_the_ID(), 'portfolio_image', true );
echo '<br>Category: '; foreach((get_the_terms($post->ID, 'portfolio-categories')) as $term) { echo $term->name. ' ,'  ; }
echo '<br>tag: '; foreach((get_the_terms($post->ID, 'portfolio-tag')) as $term) { echo $term->name. ' ,'  ; }
?>
</div>
</div>
</div>
<?php } ?>
</div>

media-uploader-post.js.js


jQuery(document).ready( function(){
function media_upload( button_class) {
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
jQuery('body').on('click',button_class, function(e) {
var button_id ='#'+jQuery(this).attr('id');
/* console.log(button_id); */
var self = jQuery(button_id);
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = jQuery(button_id);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if ( _custom_media  ) {
jQuery('.mytheme_media_url').val(attachment.url);
} else {
return _orig_send_attachment.apply( button_id, [props, attachment] );
}
}
wp.media.editor.open(button);
return false;
});
}
media_upload( '.mytheme_media_upload');
});

Taxonomy and Tags for Custom post type

Tags and Taxonomy both are using register_taxonomy() function.

if you want to display Taxonomy so ‘hierarchical’      => true,

if you want to display Tags so ‘hierarchical’      => false,


/***** Adding custom post type, Texonomys, Tags - Our Team *****/
function ourteams_custom_init() {
$labels = array(
'name' => 'Our Team',
'singular_name' => 'ourteams',
'add_new' => 'Add New',
'add_new_item' => 'Add New Our Team',
'edit_item' => 'Edit Our Team',
'new_item' => 'New Our Team',
'all_items' => 'All Our Team',
'view_item' => 'View Our Team',
'search_items' => 'Search Our Team',
'not_found' => 'No plans found',
'not_found_in_trash' => 'No plans found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Our Team'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'ourteams' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title' ,'thumbnail' , 'editor' ),

'taxonomies' => array( 'members')
);

register_post_type( 'ourteams', $args );

// team Tags
$members_labels = array(
'name'              => _x( 'Members', 'taxonomy general name' ),
'singular_name'     => _x( 'Members', 'taxonomy singular name' ),
'search_items'      => __( 'Search Members' ),
'all_items'         => __( 'All Members' ),
'parent_item'       => __( 'Parent Members' ),
'parent_item_colon' => __( 'Parent Members:' ),
'edit_item'         => __( 'Edit Members' ),
'update_item'       => __( 'Update Members' ),
'add_new_item'      => __( 'Add New Members' ),
'new_item_name'     => __( 'New Members' ),
'menu_name'         => __( 'Members' ),
);

$members_labels_args = array(
'hierarchical'      => true,
'labels'            => $members_labels,
'show_ui'           => true,
'show_admin_column' => true,
'query_var'         => true,
'show_in_nav_menus' => true,
'show_tagcloud'     => true,
'rewrite'           => array( 'slug' => 'members' ),
);
register_taxonomy( 'members', array( 'ourteams' ), $members_labels_args );
}
add_action( 'init', 'ourteams_custom_init' );

Display Post by Category

/* Show posts associated with certain categories.
cat (int) – use category id.
category_name (string) – use category slug (NOT name).
category__and (array) – use category id.
category__in (array) – use category id.
category__not_in (array) – use category id. */

// If You are Using Custom post type so you have to use ‘tax_query’


$args_ourteams=array(
'post_type' => 'ourteams',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'members',
//'field' => 'term_id',
//'terms' => 10,
'field' => 'slug',
'terms' => 'attorneys'
)));

$loop_ourteams = new WP_Query($args_ourteams);

while ($loop_ourteams->have_posts()) : $loop_ourteams->the_post();

the_title();

endwhile;

Display Posts by Category


$lattest_args7 = array(
'post_type' => 'post',
'posts_per_page' => 5,
'cat' => 6
);
$lattest_loop7 = new WP_Query($lattest_args7);

while($lattest_loop7->have_posts()):$lattest_loop7->the_post();
echo get_the_title();

endwhile;

Custom Post type with taxonomy and metabox

Functions.php


function realestate_custom_posttype()
{

/* To add CPT Listings*/
$realestate_listings_labels = array(
'name' => 'Listings',
'singular_name' => 'listing',
'add_new' => 'Add New',
'add_new_item' => 'Add New',
'edit_item' => 'Edit Listing',
'new_item' => 'New Listing',
'all_items' => 'Listings',
'view_item' => 'View Listing',
'search_items' => 'Search Listing',
'not_found' => 'No Listing found',
'not_found_in_trash' => 'No Listing found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Listings'
);

$realestate_listings_args = array(
'labels' => $realestate_listings_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'menu_icon' => get_template_directory_uri(). '/images/listing_icon.png',
'rewrite' => array( 'slug' => 'listing' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail'),
'taxonomies' => array( 'features')
);

register_post_type( 'listing', $realestate_listings_args );

$realestate_feature_labels = array(
'name' => _x( 'Features', 'taxonomy general name' ),
'singular_name' => _x( 'Feature', 'taxonomy singular name' ),
'search_items' => __( 'Search Features' ),
'all_items' => __( 'All Features' ),
'parent_item' => __( 'Parent Features' ),
'parent_item_colon' => __( 'Parent Features:' ),
'edit_item' => __( 'Edit Feature' ),
'update_item' => __( 'Update Feature' ),
'add_new_item' => __( 'Add New Feature' ),
'new_item_name' => __( 'New Feature' ),
'menu_name' => __( 'Features' ),
);

$realestate_feature_args = array(
'hierarchical' => false,
'labels' => $realestate_feature_labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => array( 'slug' => 'features' ),
);
register_taxonomy( 'features', array( 'listing' ), $realestate_feature_args );
}
add_action( 'init', 'realestate_custom_posttype' );
function listing_meta_box(){
add_meta_box('property_info', __( 'Property Details', 'realestate' ), 'property_info', 'listing', 'normal', 'low');
add_meta_box('attachments_info',__( 'Extra Image', 'realestate' ), 'attachments_info', 'listing', 'normal', 'low');
add_meta_box('contact_info',__( 'Contact Information', 'realestate' ), 'contact_info', 'listing', 'normal', 'low');
add_meta_box('featured_info',__( 'Featured Property', 'realestate' ), 'featured_info', 'listing', 'side', 'low');
}
add_action("add_meta_boxes", "listing_meta_box");

function featured_info(){
global $post;
$realestate_featured = get_post_meta($post->ID,'featured',true)?get_post_meta($post->ID,'featured',true):'';
$realestate_checked='';
if($realestate_featured != '')
$realestate_checked='checked';
?>
<table class="form-table">
<tr>
<td><label for="featured"><b><?php _e('Featured','realestate'); ?>:</b></label>
<input type="checkbox" name="featured" value="Y" <?php echo $realestate_checked; ?> class="listing_input" /></td>
</tr>
</table>
<?php

}
function property_info() {

global $post;
$realestate_property_type = get_post_meta($post->ID,'property_type',true)?get_post_meta($post->ID,'property_type',true):'';
$realestate_list_type = get_post_meta($post->ID,'list_type',true)?get_post_meta($post->ID,'list_type',true):'';
$realestate_duration = get_post_meta($post->ID,'duration',true)?get_post_meta($post->ID,'duration',true):'';
$realestate_rooms = get_post_meta($post->ID,'rooms',true)?get_post_meta($post->ID,'rooms',true):'';
$realestate_sq_ft = get_post_meta($post->ID,'sq_ft',true)?get_post_meta($post->ID,'sq_ft',true):'';
$realestate_price = get_post_meta($post->ID,'price',true)?get_post_meta($post->ID,'price',true):'0';
$realestate_rooms = get_post_meta($post->ID,'rooms',true)?get_post_meta($post->ID,'rooms',true):'';
$realestate_bedroom = get_post_meta($post->ID,'bedroom',true)?get_post_meta($post->ID,'bedroom',true):'';
$realestate_bathroom = get_post_meta($post->ID,'bathroom',true)?get_post_meta($post->ID,'bathroom',true):'';
$realestate_address = get_post_meta($post->ID,'address',true)?get_post_meta($post->ID,'address',true):'';
?>

<table class="form-table">
<tr>
<th><label for="property_type">
<?php _e('Property Type','realestate'); ?>
</label></th>

<td>
<select id="property_type" name="property_type" class="listing_input">
<option value="Apartment" <?php if($realestate_property_type == "Apartment"){?> selected="selected"<?php } ?>>Apartment</option>
<option value="House" <?php if($realestate_property_type == "House"){?> selected="selected"<?php } ?>>House</option>
<option value="Office" <?php if($realestate_property_type == "Office"){?> selected="selected"<?php } ?>>Office</option>
<option value="Villa" <?php if($realestate_property_type == "Villa"){?> selected="selected"<?php } ?>>Villa</option>
</select>
</td>
</tr>
<tr>
<th><label for="list_type">
<?php _e('Listing Type','realestate'); ?>
</label></th>
<td><select id="list_type" name="list_type" class="listing_input change_listtype">
<option value="rent" <?php if($realestate_list_type == "rent"){?> selected="selected"<?php } ?>>For Rent</option>
<option value="sale" <?php if($realestate_list_type == "sale"){?> selected="selected"<?php } ?>>For Sale</option>
</select></td>
</tr>
<tr>
<th><label for="sq_ft">
<?php _e('Square Feet','realestate'); ?>
</label></th>
<td><input type="number" name="sq_ft" value="<?php echo $realestate_sq_ft; ?>" min="0" step="any" class="listing_input" /></td>
</tr>
<tr id="duration-tr" class="hide-duration">
<th><label for="duration">
<?php _e('Duration','realestate'); ?>
</label></th>
<td><select id="duration" name="duration" class="listing_input">
<option value="week" <?php if($realestate_duration == "week"){?> selected="selected"<?php } ?>>Weekly</option>
<option value="month" <?php if($realestate_duration == "month"){?> selected="selected"<?php } ?>>Monthly</option>
<option value="year" <?php if($realestate_duration == "year"){?> selected="selected"<?php } ?>>yearly</option>
</select></td>
</tr>
<tr>
<th><label for="price">
<?php _e('Price','realestate'); ?>
</label></th>
<td><input type="number" name="price" value="<?php echo $realestate_price; ?>" min="0" step="any" class="listing_input" /></td>
</tr>
<tr>
<th><label for="rooms">
<?php _e('Rooms','realestate'); ?>
</label></th>
<td><input type="text" name="rooms" value="<?php echo $realestate_rooms; ?>" class="listing_input" /></td>
</tr>

<tr>
<th><label for="bedroom">
<?php _e('Bedrooms','realestate'); ?>
</label></th>
<td><input type="number" name="bedroom" value="<?php echo $realestate_bedroom; ?>" min=="0" class="listing_input" /></td>
</tr>
<tr>
<th><label for="bathroom">
<?php _e('Bathrooms','realestate'); ?>
</label></th>
<td><input type="number" name="bathroom" value="<?php echo $realestate_bathroom; ?>" min="0" class="listing_input" /></td>
</tr>
<tr>
<th><label for="address">
<?php _e('Address','realestate'); ?>
</label></th>
<td><textarea name="address" class="listing_input" /><?php echo $realestate_address; ?></textarea></td>
</tr>
</table>
<?php
}
function attachments_info(){
global $post;
$realestate_image1 = get_post_meta($post->ID,'image1',true)?get_post_meta($post->ID,'image1',true):'';
$realestate_image2 = get_post_meta($post->ID,'image2',true)?get_post_meta($post->ID,'image2',true):'';
$realestate_image3 = get_post_meta($post->ID,'image3',true)?get_post_meta($post->ID,'image3',true):'';
?>
<table class="form-table">
<tr>
<th><label for="image1">
<?php _e('Image 1 ','realestate'); ?>
</label></th>
<td><div class="section section-upload ">
<input id="image1" class="upload listing_input_upload" type="text" name="image1" value="<?php echo $realestate_image1; ?>" placeholder="No file chosen" />
<input id="upload_image_button" class="upload-button button" type="button" value="Upload" />
<div class="screenshot" id="logo-image">
<?php if(!empty($realestate_image1)){
echo "<a href='".$realestate_image1."' target='_blank'><img src='".$realestate_image1."' /></a><a class='remove-image'>Remove</a>" ;
}
?>
</div>
</div></td>
</tr>

<tr>
<th><label for="image2">
<?php _e('Image 2 ','realestate'); ?>
</label></th>
<td><div class="section section-upload ">
<input id="image2" class="upload listing_input_upload" type="text" name="image2" value="<?php echo $realestate_image2; ?>" placeholder="No file chosen" />
<input id="upload_image_button" class="upload-button button" type="button" value="Upload" />
<div class="screenshot" id="logo-image">
<?php if(!empty($realestate_image2)){
echo "<a href='".$realestate_image2."' target='_blank'><img src='".$realestate_image2."' /></a><a class='remove-image'>Remove</a>" ;
}
?>
</div>
</div></td>
</tr>

<tr>
<th><label for="image3">
<?php _e('Image 3 ','realestate'); ?>
</label></th>
<td><div class="section section-upload ">
<input id="image3" class="upload listing_input_upload" type="text" name="image3" value="<?php echo $realestate_image3; ?>" placeholder="No file chosen" />
<input id="upload_image_button" class="upload-button button" type="button" value="Upload" />
<div class="screenshot" id="logo-image">
<?php if(!empty($realestate_image3)){
echo "<a href='".$realestate_image3."' target='_blank'><img src='".$realestate_image3."' /></a><a class='remove-image'>Remove</a>" ;
}
?>
</div>
</div></td>
</tr>

</table>
<?php

}
function contact_info() {

global $post;
$realestate_name = get_post_meta($post->ID,'name',true)?get_post_meta($post->ID,'name',true):'';
$realestate_email = get_post_meta($post->ID,'email',true)?get_post_meta($post->ID,'email',true):'';
$realestate_phone = get_post_meta($post->ID,'phone',true)?get_post_meta($post->ID,'phone',true):'';
$realestate_mobile= get_post_meta($post->ID,'mobile',true)?get_post_meta($post->ID,'mobile',true):'';
$realestate_fax= get_post_meta($post->ID,'fax',true)?get_post_meta($post->ID,'fax',true):'';
?>

<table class="form-table">
<tr>
<th><label for="name">
<?php _e('Contact Name','realestate'); ?>
</label></th>
<td><input type="text" name="name" value="<?php echo $realestate_name; ?>" class="listing_input" /></td>
</tr>

<tr>
<th><label for="email">
<?php _e('Contact Email','realestate'); ?>
</label></th>
<td><input type="text" name="email" value="<?php echo $realestate_email; ?>" class="listing_input" /></td>
</tr>
<tr>
<th><label for="phone">
<?php _e('Contact Phone','realestate'); ?>
</label></th>
<td><input type="text" name="phone" value="<?php echo $realestate_phone; ?>" class="listing_input" /></td>
</tr>
<tr>
<th><label for="mobile">
<?php _e('Contact Mobile','realestate'); ?>
</label></th>
<td><input type="text" name="mobile" value="<?php echo $realestate_mobile; ?>" class="listing_input" /></td>
</tr>
<tr>
<th><label for="fax">
<?php _e('Contact Fax','realestate'); ?>
</label></th>
<td><input type="text" name="fax" value="<?php echo $realestate_fax; ?>" class="listing_input" /></td>
</tr>

</table>
<?php
}
add_action('save_post', 'realestate_property_save_details');
function realestate_property_save_details(){
global $post;
if(!empty($_POST))
{
//featured_info
update_post_meta($post->ID, "featured", $_POST["featured"]);
//Property Details:
update_post_meta($post->ID, "property_type", $_POST["property_type"]);
update_post_meta($post->ID, "list_type", $_POST["list_type"]);
update_post_meta($post->ID, "duration", $_POST["duration"]);
update_post_meta($post->ID, "sq_ft", $_POST["sq_ft"]);
update_post_meta($post->ID, "price", filter_var($_POST["price"],FILTER_SANITIZE_NUMBER_FLOAT));
update_post_meta($post->ID, "rooms", filter_var($_POST["rooms"],FILTER_SANITIZE_NUMBER_FLOAT));
update_post_meta($post->ID, "bedroom", filter_var($_POST["bedroom"],FILTER_SANITIZE_NUMBER_FLOAT));
update_post_meta($post->ID, "bathroom", filter_var($_POST["bathroom"],FILTER_SANITIZE_NUMBER_FLOAT));
update_post_meta($post->ID, "address", $_POST["address"]);
//address details
update_post_meta($post->ID, "floorno", $_POST["floorno"]);
update_post_meta($post->ID, "b_name", $_POST["b_name"]);
update_post_meta($post->ID, "street", $_POST["street"]);
update_post_meta($post->ID, "zipcode", $_POST["zipcode"]);
update_post_meta($post->ID, "city", $_POST["city"]);
update_post_meta($post->ID, "county", $_POST["county"]);
update_post_meta($post->ID, "state", $_POST["state"]);
update_post_meta($post->ID, "country", $_POST["country"]);

//contact info
update_post_meta($post->ID, "disp_contact", $_POST["disp_contact"]);
update_post_meta($post->ID, "name", $_POST["name"]);
update_post_meta($post->ID, "email",sanitize_email($_POST['email']));
update_post_meta($post->ID, "phone", $_POST["phone"]);
update_post_meta($post->ID, "mobile", $_POST["mobile"]);
update_post_meta($post->ID, "fax", $_POST["fax"]);

//attachments
update_post_meta($post->ID, "image1", $_POST["image1"]);
update_post_meta($post->ID, "image2", $_POST["image2"]);
update_post_meta($post->ID, "image3", $_POST["image3"]);
}
}

 

JS file for Uploading Image


(function($) {
$(document).ready(function() {

function realestate_add_file(event, selector) {

var upload = $(".uploaded-file"), frame;
var $el = $(this);

event.preventDefault();

// If the media frame already exists, reopen it.
if ( frame ) {
frame.open();
return;
}

// Create the media frame.
frame = wp.media({
// Set the title of the modal.
title: $el.data('choose'),

// Customize the submit button.
button: {
// Set the text of the button.
text: $el.data('update'),
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
});

// When an image is selected, run a callback.
frame.on( 'select', function() {
// Grab the selected attachment.
var attachment = frame.state().get('selection').first();
frame.close();
selector.find('.upload').val(attachment.attributes.url);
if ( attachment.attributes.type == 'image' ) {
selector.find('.screenshot').empty().hide().append('<img src="' + attachment.attributes.url + '"><a class="remove-image"></a>').slideDown('fast');
}
selector.find('.upload-button').unbind().addClass('remove-file').removeClass('upload-button');
selector.find('.of-background-properties').slideDown();
selector.find('.remove-image, .remove-file').on('click', function() {
realestate_remove_file( $(this).parents('.section') );
});
});

// Finally, open the modal.
frame.open();
}

function realestate_remove_file(selector) {
selector.find('.remove-image').hide();
selector.find('.upload').val('');
selector.find('.of-background-properties').hide();
selector.find('.screenshot').slideUp();
selector.find('.remove-file').unbind().addClass('upload-button').removeClass('remove-file');
// We don't display the upload button if .upload-notice is present
// This means the user doesn't have the WordPress 3.5 Media Library Support
if ( $('.section-upload .upload-notice').length > 0 ) {
$('.upload-button').remove();
}
selector.find('.upload-button').live('click', function() {
realestate_add_file(event, $(this).parents('.section'));
});
}

$('.remove-image, .remove-file').live('click', function() {
realestate_remove_file( $(this).parents('.section') );
});

$('.upload-button').live('click', function( event ) {
realestate_add_file(event, $(this).parents('.section'));
});

});
/*for custom post type media upload*/
if(jQuery('#list_type').val() == 'rent')
jQuery('#duration-tr').removeClass( "hide-duration");
jQuery(".change_listtype").change(function($)
{
if(jQuery('#list_type').val() == 'rent')
jQuery('#duration-tr').removeClass( "hide-duration");
else
jQuery('#duration-tr').addClass( "hide-duration");

});
/*end*/

})(jQuery);

CSS Style and also  add remove image in images folder

<

div class=”cssRule cssEditableRule insertInto editGroup “>

</div>
<div class="cssHead focusRow "><span class="cssSelector editable ">.screenshot .remove-image</span> {</div>
<div class=" ">
<div class="cssPropertyListBox ">
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">background</span><span class="cssColon ">: </span><span class="cssPropValue editable ">rgba(0, 0, 0, 0) url("../images/ico-delete.png") no-repeat scroll 0 0</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">border</span><span class="cssColon ">: </span><span class="cssPropValue editable ">medium none</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">bottom</span><span class="cssColon ">: </span><span class="cssPropValue editable ">4px</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">display</span><span class="cssColon ">: </span><span class="cssPropValue editable ">block</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">float</span><span class="cssColon ">: </span><span class="cssPropValue editable ">left</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">height</span><span class="cssColon ">: </span><span class="cssPropValue editable ">16px</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">padding</span><span class="cssColon ">: </span><span class="cssPropValue editable ">0</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">position</span><span class="cssColon ">: </span><span class="cssPropValue editable ">absolute</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">right</span><span class="cssColon ">: </span><span class="cssPropValue editable ">-4px</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">text-indent</span><span class="cssColon ">: </span><span class="cssPropValue editable ">-9999px</span><span class="cssSemi ">;</span></div>
<div class="cssProp focusRow editGroup "><span class="cssPropIndent ">    </span><span class="cssPropName editable ">width</span><span class="cssColon ">: </span><span class="cssPropValue editable ">16px</span><span class="cssSemi ">;</span></div>
</div>
</div>
<div class=" editable insertBefore ">}</div>
</div>
<div class=" editable insertBefore "> 
Display Posts in Page Template
</div>
<div class=" editable insertBefore "><?php
/*
Template Name:Property Page
*/
?>
<?php
get_header();
?>
<section>
<div class="breadcumb-bg">
<div class="webpage-container container">
<div class="site-breadcumb">
<h1><?php _e('Property', 'realestate'); ?></h1>
<ol class="breadcrumb breadcrumb-menubar">
<?php if (function_exists('realestate_custom_breadcrumbs')) realestate_custom_breadcrumbs(); ?>
</ol>
</div>
</div>
</div>
<?php
$property_array = $list_array = $room_array = $realestate_bathrooms_array = $realestate_bedrooms_array = $realestate_from_array = $realestate_to_array = '';
$realestate_from = $realestate_to = $realestate_price = $realestate_bathrooms = $realestate_bedrooms = $realestate_rooms = '';if (isset($_REQUEST)) {
$realestate_property_type = $_REQUEST['property_type'];
$realestate_list_type = $_REQUEST['list_type'];
$realestate_rooms = $_REQUEST['rooms'];
$realestate_bathrooms = $_REQUEST['bathrooms'];
$realestate_bedrooms = $_REQUEST['bedrooms'];
$realestate_myprice = $_REQUEST['myamount'];
$realestate_features_request = $_REQUEST['feature'];
if (!empty($realestate_features_request)) {
$realestate_features = implode(",", $realestate_features_request);
$realestate_features_array = array(
'taxonomy' => 'features',
'field' => 'id',
'terms' => $realestate_features,
'operator' => 'AND'
);
}
if ($realestate_myprice != '') {
$realestate_price = explode("-", $realestate_myprice);
$realestate_from = $realestate_price[0];
$realestate_to = $realestate_price[1];
}
if ($realestate_property_type != '') {
$property_array = array(
'key' => 'property_type',
'value' => $realestate_property_type,
);
}
if ($realestate_list_type != '') {
$list_array = array(
'key' => 'list_type',
'value' => $realestate_list_type,
);
}
if ($realestate_rooms != 0) {
if ($realestate_rooms == 5) {
$room_array = array(
'key' => 'rooms',
'value' => $realestate_rooms,
'type' => 'numeric',
'compare' => '>=',
);
} else {
$room_array = array(
'key' => 'rooms',
'value' => $realestate_rooms,
);
}
}
if ($realestate_bathrooms != 0) {
if ($realestate_bathrooms == 5) {
$realestate_bathrooms_array = array(
'key' => 'bathroom',
'value' => $realestate_bathrooms,
'type' => 'numeric',
'compare' => '>=',
);
} else {
$realestate_bathrooms_array = array(
'key' => 'bathroom',
'value' => $realestate_bathrooms,
);
}
}
if ($realestate_bedrooms != 0) {
if ($realestate_bedrooms == 5) {
$realestate_bedrooms_array = array(
'key' => 'bedroom',
'value' => $realestate_bedrooms,
'type' => 'numeric',
'compare' => '>=',
);
} else {
$realestate_bedrooms_array = array(
'key' => 'bedroom',
'value' => $realestate_bedrooms,
);
}
}
if (!empty($realestate_myprice)) {
$realestate_from_array = array(
'key' => 'price',
'value' => $realestate_from,
'type' => 'numeric',
'compare' => '>=',
);
}
if (!empty($realestate_myprice)) {
$realestate_to_array = array(
'key' => 'price',
'value' => $realestate_to,
'type' => 'numeric',
'compare' => '<=',
);
}
}
?>

<?php
$paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1;
$realestate_args = array(
'paged' => $paged,
'post_type' => 'listing',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
$property_array, $list_array, $room_array, $realestate_bathrooms_array, $realestate_bedrooms_array, $realestate_from_array, $realestate_to_array),
'tax_query' => array(
'relation' => 'AND',
$realestate_features_array)
);
$realestate_arrays1 = new WP_Query($realestate_args);
?>
<div class="webpage-container">
<div class="property-blog-page">
<div class="recent-listings">

<?php while ($realestate_arrays1->have_posts()) : $realestate_arrays1->the_post(); ?>
<?php
$realestate_property_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'realestate-property-tab-size');
if (empty($realestate_property_image)) {
for ($realestate_i = 1; $realestate_i <= 3; $realestate_i++) {
$realestate_key = 'image' . $realestate_i;
$realestate_image = get_post_meta(get_the_ID(), $realestate_key, true);
if (!empty($realestate_image)) {
$realestate_image_id = realestate_get_image_id($realestate_image);
$realestate_property_image = wp_get_attachment_image_src($realestate_image_id, 'realestate-property-tab-size');
break;
}
}
}
if (!empty($realestate_property_image)) {
?>
<div class="col-md-4 col-sm-6 blog-post blog-post">
<div class="col-md-12 no-padding-lr listing-details">

<a href="<?php the_permalink(); ?>"><img src="<?php echo $realestate_property_image[0]; ?>" width="<?php echo $realestate_property_image[1]; ?>" height="<?php echo $realestate_property_image[2]; ?>" alt="<?php the_title(); ?>"></a>
<div class="property-details">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<ul>
<?php $realestate_sqft = get_post_meta(get_the_ID(), 'sq_ft', true);
if (!empty($realestate_sqft)) {
?>
<li><?php echo $realestate_sqft; ?> <?php _e('Sq Ft', 'realestate'); ?></li>
<?php } ?>
<?php $realestate_bathrooms = get_post_meta(get_the_ID(), 'bathroom', true);
if (!empty($realestate_bathrooms)) {
?>
<li><?php echo $realestate_bathrooms; ?> <?php _e('Bathrooms', 'realestate'); ?></li>
<?php } ?>
<?php $realestate_bedrooms = get_post_meta(get_the_ID(), 'bedroom', true);
if (!empty($realestate_bedrooms)) {
?>
<li><?php echo $realestate_bedrooms; ?> <?php _e('Bedrooms', 'realestate'); ?></li>
<?php } ?>
</ul>
<?php
$realestate_price = get_post_meta(get_the_ID(), 'price', true);
if (!empty($realestate_price)) {
?>
<a href="<?php the_permalink(); ?>" class="ref-link">$<?php echo $realestate_price ?></a>
<?php } ?>

<a href="<?php the_permalink(); ?>" class="ref-link"><?php _e('Details', 'realestate'); ?></a>
</div>
</div>
</div>
<?php } ?>

<?php endwhile; ?>
<div class="col-md-12 no-padding-lr">
<div class="pagination">
<?php realestate_custom_pagination($realestate_arrays1->max_num_pages, '2'); ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>

Post by custom days without array

This is under plugins function

http://wordpress.stackexchange.com/questions/54142/check-post-date-in-pre-get-posts

query_posts(array(
‘post_type’ => ‘movies’,
‘event_categories’ => $spot_category,
‘posts_per_page’ => -1
));

Now i add in functions.php using hook

http://devotepress.com/wordpress-coding/when-to-use-pre_get_posts-in-wordpress/#.VO8EaTWli1G

function popular_posts_weekly_custom($query) {
if (function_exists(‘vh_spotlight’)){
$today = getdate();
$query->set( ‘orderby’, ‘comment_count’);
$query->set( ‘day’, $today[‘mday’] );
}
}
add_action( ‘pre_get_posts’, ‘popular_posts_weekly_custom’ );

%d bloggers like this: