I'm using this code to get data from text type metabox.. This will create an array
$args = array('post_type' => 'locations_add');
$prefix = 'nilgiris_';
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()):
$the_query->the_post();
$l_names[] = rwmb_meta($prefix . 'l_name');
$lo_name = array();
foreach( $l_names as $l_namea ){
$lo_name[] = array(
$l_namea => $l_namea
);
}
endwhile;
endif;
My problem is that when using the wp_query function along with metabox the metabox will not load..
Hers is the entire code
<?php
$args = array('post_type' => 'locations_add');
$prefix = 'nilgiris_';
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()):
$the_query->the_post();
$l_names[] = rwmb_meta($prefix . 'l_name');
$lo_name = array();
foreach( $l_names as $l_namea ){
$lo_name[] = array(
$l_namea => $l_namea
);
}
endwhile;
endif;
add_filter('rwmb_meta_boxes', 'website_register_meta_boxes');
function website_register_meta_boxes($meta_boxes) {
$prefix = 'nilgiris_';
$meta_boxes[] = array(
'id' => 'location_types',
'title' => __('location name', $prefix),
'post_types' => array('locations_add'),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
// List of meta fields
'fields' => array(
array(
'name' => __('Enter Location Name', $prefix),
'id' => "{$prefix}l_name",
'desc' => __('Enter name', $prefix),
'type' => 'text',
//'clone' => true,
),
),
);
$meta_boxes[] = array(
'id' => 'location_types',
'title' => __('location name', $prefix),
'post_types' => array('Hotels'),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __('Enter Location Name', $prefix),
'id' => "{$prefix}H_name",
'desc' => __('Enter name', $prefix),
'type' => 'text',
),
array(
'name' => __('Checkbox list', '$prefix'),
'id' => "{$prefix}H_list",
'type' => 'select',
**'options' => $lo_name,**
),
),
);
return $meta_boxes;
}
Related
I am getting null response on the below query. I am trying to get sum of the products subtotal and a custom cost field for products. I am able to get the data fine without the where clause but getting NULL with the where clause. The where clause is for getting the orders that have the custom meta 'dropshipper_name' in it with a specific meta_value.
$this->report_data->order_totals = (array) $this->get_order_report_data(
array(
'data' => array(
'_cost_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => '_alg_wc_cog_cost',
),
'_profit_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => '_line_subtotal',
),
),
'where_meta' => array(
array(
'meta_key' => 'dropshipper_name',
'meta_value' => 'alex',
'operator' => '=',
),
),
'filter_range' => true,
'order_status' => array( 'completed', 'processing', 'on-hold', 'pending' ),
)
);
include_once(WC()->plugin_path().'/includes/admin/reports/class-wc-admin-report.php');
add_filter( 'woocommerce_admin_reports', 'my_custom_woocommerce_admin_reports', 10, 1 );
function my_custom_woocommerce_admin_reports( $reports ) {
$sales_by_ebay_payment = array(
'sales_by_ebay_payment' => array(
'title' => 'Sales By Ebay Payment',
'description' => '',
'hide_title' => true,
'callback' => 'sales_by_ebay_payment_callback',
),
);
// This can be: orders, customers, stock or taxes, based on where we want to insert our new reports page
$reports['orders']['reports'] = array_merge( $reports['orders']['reports'], $sales_by_ebay_payment);
return $reports;
}
function sales_by_ebay_payment_callback() {
$report = new WC_Report_Sales_By_Ebay_Payment();
$report->output_report();
}
class WC_Report_Sales_By_Ebay_Payment extends WC_Admin_Report {
/**
* Output the report.
*/
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
);
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'month';
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', '7day' ) ) ) {
$current_range = 'month';
}
$this->check_current_range_nonce( $current_range );
$this->calculate_current_range( $current_range );
$hide_sidebar = true;
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
}
/**
* Get the main chart.
*/
public function get_main_chart() {
global $wpdb;
$where_meta = array();
$query_data = array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
'distinct' => true,
),
'_payment_method' => array(
'type' => 'meta',
'function' => '',
'name' => 'Ebay'
),
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'order_total'
),
);
$where_meta[] = array(
'meta_key' => '_payment_method',
'meta_value' =>'ebay_managed_payment',
'operator' => '=',
'type' => 'meta'
);
$sales_by_country_orders = $this->get_order_report_data( array(
'data' => $query_data,
'query_type' => 'get_results',
'group_by' => 'Ebay',
'where_meta' => $where_meta,
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed' ),
'parent_order_status' => false,
) );
//echo "<pre>";
//print_r($sales_by_country_orders);
?>
<table class="widefat">
<thead>
<tr>
<th><strong>Payment Method</strong></th>
<th><strong>Number Of Orders</strong></th>
<th><strong>Sales</strong></th>
</tr>
</thead>
<tbody>
<?php foreach( $sales_by_country_orders as $order ) {
?>
<tr>
<td><?php echo $order->Ebay; ?></td>
<td><?php echo $order->total_orders; ?></td>
<td><?php echo wc_price($order->order_total); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
}
I'm trying to put in place a sortable field where the options value are the page titles,
I'm using Kirki plugin,
How can i do that ?
here's is the code
Thanks a lot for your time
Using theme_mods or options?
theme_mods
Code to reproduce the issue (config + field(s))
<?php
$pages = get_pages();
foreach ($pages as $page ) {
$pages_list[] = array ('id' => $page->ID, 'title' => $page->post_title);
};
print_r($pages_list);
Kirki::add_field( 'my_config', array(
'type' => 'sortable',
'settings' => 'my_setting',
'label' => __( 'This is the label', 'my_textdomain' ),
'section' => 'my_section',
'default' => array(
'option3',
'option1',
'option4'
),
'choices' => $pages_list,
'priority' => 10,
) );
?>
got it !
$pages_array = array();
$get_pages = get_pages( 'hide_empty=0' );
foreach ( $get_pages as $page ) {
$pages_array[$page->ID] = esc_attr( $page->post_title );
}
Kirki::add_field( '_s_theme', array(
'type' => 'sortable',
'settings' => 'sort',
'label' => __( 'This is the label', 'my_textdomain' ),
'section' => 'sections',
'default' => array(),
'choices' => $pages_array,
'priority' => 10,
) );
Hey there. I am creating a Wordpress theme and was wondering if anyone knew of a way to list one of my custom post types in the theme customiser. I have a custom post type called "slideshow" that has custom meta boxes etc and is designed just for slideshows. I would like to be able to list these posts in a dropdown inside the customiser. Ideally ending up with them in the array like this...
'the_id' => 'Slideshow post title',
$wp_customize->add_setting(
'slideshow-homepage',
array(
'default' => 'none',
)
);
$wp_customize->add_control(
'slideshow-homepage',
array(
'type' => 'select',
'priority' => 3,
'label' => 'Slideshow',
'description' => '',
'section' => 'homepage',
'choices' => array(
'somehow' => 'somehow',
'list' => 'list',
'all' => 'all',
'custom' => 'custom',
'post' => 'post',
'types' => 'types',
'of' => 'of',
'type' => 'type',
'slideshow' => 'slideshow'
),
)
);
Many thanks guys and girls. Lewis
use array_reduce
$wp_customize->add_control(
'slideshow-homepage',
array(
'type' => 'select',
'priority' => 3,
'label' => 'Slideshow',
'description' => '',
'section' => 'homepage',
'choices' => array_reduce(
get_posts( 'post_type=slideshow&posts_per_page=-1' ),
function( $result, $item ) {
$result[$item->ID] = $item->post_title;
return $result;
}
),
)
);
To add an empty field as well:
$posts = array_reduce(
get_posts( 'post_type=slideshow&posts_per_page=-1' ),
function( $result, $item ) {
$result[$item->ID] = $item->post_title;
return $result;
}
);
$none = array('' => 'None');
$choices = $none + $posts;
$wp_customize->add_control('slideshow_control', array(
'label' => __('Choose Slideshow', 'themename'),
'section' => 'slideshow_option',
'settings' => 'slideshow_settings',
'type' => 'select',
'choices' => $choices
));
hello I am using reusable custom metaboxes from https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes..
these are my fields
array(
'label' => __('Setup Slider', 'crispy' ),
'desc' => __('create your slider image/ text using these repeatable options', 'crispy' ),
'id' => $prefix.'repeatable',
'type' => 'repeatable',
'sanitizer' => array(
'title' => 'sanitize_text_field',
'desc' => 'wp_kses_data'
),
'repeatable_fields' => array (
array(
'label' => __(' Slider Text alignment', 'crispy'),
'id' => 'alignment',
'type' => 'radio',
'options' => array (
'one' => array (
'label' => __('Left', 'crispy' ),
'value' => 'left'
),
'two' => array (
'label' => __('Center', 'crispy' ),
'value' => 'center'
),
'three' => array (
'label' => __('Right', 'crispy' ),
'value' => 'right'
)
)
),
array(
'label' => __('Background Image/pattern', 'crispy' ),
'id' => 'image',
'type' => 'image'
),
array(
'label' => __('Title', 'crispy' ),
'id' => 'title',
'type' => 'text'
),
array(
'label' => __('Description', 'crispy' ),
'id' => 'desc',
'type' => 'textarea'
),
)
),
My problem is i don't know how to store the fields value... can anyone resolve my problem!!..
$home_slider_alignment = get_post_meta( $post->ID, 'alignment', true);
i used this but doesn't help!!.. Those fields can be repeatable so the values are stored in array!!.. i don't know how to retrieve stored values from that array??..
Please help me!!.
It is working :)
enter code here
<?php
$projectgallery = get_post_meta($post->ID, 'arcadia_well_projectgallery', true); {
echo '<ul class="custom_repeatable">';
foreach ($projectgallery as $project) {
echo '<li>';
foreach($project as $i=>$value) {
echo $value;
}
echo '</li>';
}
echo '</ul>';
}
?>
I am trying to get the category names into the following array
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
$this->settings['categoriesmain1'] = array(
'section' => 'general',
'title' => __( 'Example Select' ),
'desc' => __( 'This is a description for the drop-down.' ),
'type' => 'select',
'std' => '',
'choices' => array(
$categories => $categories // here i am trying to echo them
)
);
choices by default they are smth like this
'choices' => array(
'Choice 1' => 'Other Choice 1',
'Choice 2' => 'Other Choice 2',
'Choice 3' => 'Other Choice 3'
)
But when i try to echo them with $categories => $categories I get error Illegal offset type
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
);
$categories = get_categories($args);
$categories_name = array();
foreach($categories as $category){
$categories_name[] = $category->name;
}
$this->settings['categoriesmain1'] = array(
'section' => 'general',
'title' => __( 'Example Select' ),
'desc' => __( 'This is a description for the drop-down.' ),
'type' => 'select',
'std' => '',
'choices' => $categories_name
)
);
$settings = get_option('mytheme_options');
$my_choices = $settings['categoriesmain1'];
var_dump($my_choices);
Shouldnt that be:
'choices' => $categories
?
If not, you're definitely missing a step somewhere: associate each category to a key or label or whatever is needed. (The key cannot be an array: is where your error is coming from. And each category needs a key: not the array itself.)