Skip to content

Instantly share code, notes, and snippets.

@eto4detak
Created October 8, 2018 13:46
Show Gist options
  • Save eto4detak/ff35211018e7acd73a7745e6b4ba9795 to your computer and use it in GitHub Desktop.
Save eto4detak/ff35211018e7acd73a7745e6b4ba9795 to your computer and use it in GitHub Desktop.
wp php wptable
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Manage property lists
///////////////////////////////////////////////////////////////////////////////////////////////////////////
add_filter( 'manage_edit-estate_property_columns', 'wpestate_my_columns' );
if( !function_exists('wpestate_my_columns') ):
function wpestate_my_columns( $columns ) {
$slice=array_slice($columns,2,2);
unset( $columns['comments'] );
unset( $slice['comments'] );
$splice=array_splice($columns, 2);
$columns['estate_ID'] = esc_html__('ID','wpresidence-core');
$columns['estate_thumb'] = esc_html__('Image','wpresidence-core');
$columns['estate_city'] = esc_html__('City','wpresidence-core');
$columns['estate_action'] = esc_html__('Action','wpresidence-core');
$columns['estate_category'] = esc_html__( 'Category','wpresidence-core');
$columns['estate_autor'] = esc_html__('User','wpresidence-core');
$columns['estate_status'] = esc_html__('Status','wpresidence-core');
$columns['estate_price'] = esc_html__('Price','wpresidence-core');
$columns['estate_featured'] = esc_html__('Featured','wpresidence-core');
return array_merge($columns,array_reverse($slice));
}
endif; // end wpestate_my_columns
add_action( 'manage_posts_custom_column', 'wpestate_populate_columns' );
if( !function_exists('wpestate_populate_columns') ):
function wpestate_populate_columns( $column ) {
global $post;
$the_id= $post->ID;
if ( 'estate_ID' == $column ) {
echo $the_id;
}else if ( 'estate_agent_email' == $column ) {
$agent_email = get_post_meta($the_id , 'agent_email', true);
echo $agent_email;
} else if ( 'estate_agency_email' == $column ) {
$agent_email = get_post_meta($the_id , 'agency_email', true);
echo $agent_email;
}else if ( 'estate_agency_email' == $column ) {
$agent_email = get_post_meta($the_id , 'agency_email', true);
echo $agent_email;
}else if ( 'estate_developer_email' == $column ) {
$agent_email = get_post_meta($the_id , 'developer_email', true);
echo $agent_email;
}else if ( 'estate_agency_phone' == $column ) {
$agent_phone = get_post_meta($the_id , 'agency_phone', true);
$agent_mobile = get_post_meta($the_id , 'agency_mobile', true);
echo $agent_phone.' / '.$agent_mobile;
} else if ( 'estate_developer_phone' == $column ) {
$agent_phone = get_post_meta($the_id , 'developer_phone', true);
$agent_mobile = get_post_meta($the_id , 'developer_mobile', true);
echo $agent_phone.' / '.$agent_mobile;
} else if ( 'estate_agent_phone' == $column ) {
$agent_phone = get_post_meta($the_id , 'agent_phone', true);
$agent_mobile = get_post_meta($the_id , 'agent_mobile', true);
echo $agent_phone.' / '.$agent_mobile;
}else if ( 'estate_agent_city' == $column ) {
$estate_action = get_the_term_list( $the_id, 'property_city_agent', '', ', ', '');
echo ($estate_action);
} else if ( 'estate_agent_action' == $column ) {
$estate_action = get_the_term_list( $the_id, 'property_action_category_agent', '', ', ', '');
echo ($estate_action);
}else if ( 'estate_agent_category' == $column ) {
$estate_category = get_the_term_list( $the_id, 'property_category_agent', '', ', ', '');
echo ($estate_category) ;
} else if ( 'estate_agency_city' == $column ) {
$estate_action = get_the_term_list( $the_id, 'city_agency', '', ', ', '');
echo ($estate_action);
} else if ( 'estate_agency_action' == $column ) {
$estate_action = get_the_term_list( $the_id, 'action_category_agency', '', ', ', '');
echo ($estate_action);
}else if ( 'estate_agency_category' == $column ) {
$estate_category = get_the_term_list( $the_id, 'category_agency', '', ', ', '');
echo ($estate_category) ;
}else if ( 'estate_developer_city' == $column ) {
$estate_action = get_the_term_list( $the_id, 'property_city_developer', '', ', ', '');
echo ($estate_action);
} else if ( 'estate_developer_action' == $column ) {
$estate_action = get_the_term_list( $the_id, 'property_action_developer', '', ', ', '');
echo ($estate_action);
}else if ( 'estate_developer_category' == $column ) {
$estate_category = get_the_term_list( $the_id, 'property_category_developer', '', ', ', '');
echo ($estate_category) ;
}else if ( 'estate_status' == $column ) {
$estate_status = get_post_status($the_id);
if($estate_status=='publish'){
echo esc_html__('published','wpresidence-core');
}else{
echo esc_html($estate_status);
}
$pay_status = get_post_meta($the_id, 'pay_status', true);
if($pay_status!=''){
echo " | ";
if($pay_status=='paid'){
esc_html_e('PAID','wpresidence-core');
}else{
esc_html_e('Not Paid','wpresidence-core');
}
}
}else if ( 'estate_autor' == $column ) {
$temp_id= $post->ID;
$user_id=wpsestate_get_author($the_id);
$estate_autor = get_the_author_meta('display_name',$user_id);
echo '<a href="'.get_edit_user_link($user_id).'" >'.$estate_autor.'</a>';
$post->ID=$temp_id=$the_id;
}else if ( 'estate_thumb' == $column || 'estate_agent_thumb' == $column || 'estate_agency_thumb' == $column || 'estate_developer_thumb' == $column) {
$thumb_id = get_post_thumbnail_id( $the_id);
$post_thumbnail_url = wp_get_attachment_image_src($thumb_id, 'slider_thumb');
echo '<img src="'.$post_thumbnail_url[0].'" style="width:100%;height:auto;">';
}else if ( 'estate_city' == $column ) {
$estate_city = get_the_term_list( $the_id, 'property_city', '', ', ', '');
echo ($estate_city);
}else if ( 'estate_action' == $column ) {
$estate_action = get_the_term_list( $the_id, 'property_action_category', '', ', ', '');
echo ($estate_action);
}elseif ( 'estate_category' == $column ) {
$estate_category = get_the_term_list( $the_id, 'property_category', '', ', ', '');
echo ($estate_category) ;
}else if ( 'estate_price' == $column ) {
$currency = esc_html( get_option('wp_estate_currency_symbol', '') );
$where_currency = esc_html( get_option('wp_estate_where_currency_symbol', '') );
$price = floatval( get_post_meta($the_id, 'property_price', true) );
if ($price != 0) {
$price = number_format($price);
if ($where_currency == 'before') {
$price = $currency . ' ' . $price;
} else {
$price = $price . ' ' . $currency;
}
}else{
$price='';
}
echo get_post_meta($the_id, 'property_label_before', true).' '.$price.' '. get_post_meta($the_id, 'property_label', true);
}else if ( 'estate_featured' == $column ) {
$estate_featured = get_post_meta($the_id, 'prop_featured', true);
if($estate_featured==1){
$estate_featured=esc_html__('Yes','wpresidence-core');
}else{
$estate_featured=esc_html__('No','wpresidence-core');
}
echo esc_html($estate_featured);
}
}
endif; // end wpestate_populate_columns
//'manage_edit-estate_property_columns
add_filter( 'manage_edit-estate_property_sortable_columns', 'wpestate_sort_me' );
if( !function_exists('wpestate_sort_me') ):
function wpestate_sort_me( $columns ) {
$columns['estate_autor'] = 'estate_autor';
$columns['estate_featured'] = 'estate_featured';
$columns['estate_price'] = 'estate_price';
return $columns;
}
endif; // end wpestate_sort_me
add_filter( 'request', 'bs_event_date_column_orderby_core' );
function bs_event_date_column_orderby_core( $vars ) {
if ( isset( $vars['orderby'] ) && 'estate_featured' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'prop_featured',
'orderby' => 'meta_value_num'
) );
}
if ( isset( $vars['orderby'] ) && 'estate_price' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'property_price',
'orderby' => 'meta_value_num'
) );
}
if ( isset( $vars['orderby'] ) && 'estate_autor' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'orderby' => 'author'
) );
}
return $vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment