I am using the following code to add custom meta boxes to the admin of my custom post types.
<?php
$prefix = '_myType_';
global $meta_boxes;
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'myType',
'title' => 'myType Data',
'pages' => array( 'myType' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Starts',
'id' => "{$prefix}starts",
'type' => 'date',
'js_options' => array(
'appendText' => '(yyyy-mm-dd)',
'dateFormat' => 'yy-mm-dd',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => 'Ends',
'id' => "{$prefix}ends",
'type' => 'date',
'js_options' => array(
'appendText' => '(yyyy-mm-dd)',
'dateFormat' => 'yy-mm-dd',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
)
);
function YOUR_PREFIX_register_meta_boxes()
{
if ( !class_exists( 'RW_Meta_Box' ) )
return;
global $meta_boxes;
foreach ( $meta_boxes as $meta_box )
{
new RW_Meta_Box( $meta_box );
}
}
add_action( 'admin_init', 'YOUR_PREFIX_register_meta_boxes' );
I have quite a few fields and I need a way to group the items together with something like a hr tag.
And for some reason i thought this would work
array(
'id' => 'box_1_hr',
'name' => 'box_1_hr',
'type' => 'hr',
'options' => array(
'width' => '100%',
'color' => '#DFDFDF'
)
),
But it didnt!
Doesnt anyone have any ideas if this can be done?
Thanks
Related
can we add ACF fields to custom admin_menu page?
so I have created an admin page as shown
add_action( 'admin_menu', 'opt_add_admin_menu' );
function opt_add_admin_menu( ) {
add_menu_page( 'opt', 'opt', 'manage_options', 'opt', 'opt_options_page' );
}
so next I need to add an ACF field to this options page
I got this code from ACF but the location still makes a problem for me
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6335ef4ab316e',
'title' => 'justfortest',
'fields' => array(
array(
'key' => 'field_6335ef5351c1c',
'label' => 'text',
'name' => 'text',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
'location' => array(
array(
array(
'param' => 'post_type', /* here we need to target the menu options page */
'operator' => '==',
'value' => 'post', /* here to */
),
),
),
I know how to add fields programmatically without ACF but if there is a way to add through ACF it will be so helpful
Create new admin page using acf option page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'opt',
'menu_title' => 'opt',
'menu_slug' => 'opt-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
and select option page ->opt while adding new group
--- You need acf pro version to use this feature
can anyone help me with this problem?
I had a LINE Messenger BOT, and I want to implement foreach() loop to show a list from the database I have. but I struggle with the code. here is what I wrote
function indexflex($title,$label,$text){
$data = $this->Dbs->getdata_kamusengineer()->result();
foreach ($data as $d) {
$dariindo=$d->dariindo;
$bajep=$d->bajep;
$arraynumber= 0;
$itemindeks=array (
'type' => 'box',
'layout' => 'vertical',
'contents' => array (
$arraynumber++ => array (
'type' => 'box',
'layout' => 'horizontal',
'contents' => array (
0 => array (
'type' => 'text',
'text' => $dariindo,
'align' => 'center',
'wrap' => true,
'gravity' => 'center',
'contents' => array (
),
),
1 => array (
'type' => 'separator',
'margin' => 'sm',
'color' => '#000000FF',
),
2 => array (
'type' => 'text',
'text' => $bajep,
'align' => 'center',
'align' => 'center',
'wrap' => true,
'gravity' => 'center',
'contents' =>
array (
),
),
),
),
),
);
}
$item = array (
'type' => 'bubble',
'direction' => 'ltr',
'header' => array (
'type' => 'box',
'layout' => 'vertical',
'contents' => array (
0 => array (
'type' => 'text',
'text' => $title,
'weight' => 'bold',
'align' => 'center',
'wrap' => true,
'contents' =>
array (
),
),
),
),
'body' => $itemindeks,
'footer' => array (
'type' => 'box',
'layout' => 'horizontal',
'contents' => array (
0 => array (
'type' => 'button',
'action' => array (
'type' => 'message',
'label' => $label,
'text' => $text,
),
'style' => 'primary',
),
),
),
);
return $item;
}
but the result not what i want, it just shows one of my data from many.
image of the result
can anyone help me what's wrong with this code?
Thanks,
I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!
I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!
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>';
}
?>