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,
) );
Related
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;
}
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
));
Is it possible to update wordpress blogname and blogdescription via Redux framework.
array(
'id' => 'blogdescription',
'type' => 'text',
'title' => 'Blog Description',
'default' => '',
),
You can use update_option(); function
update_option( 'blogname', 'New Value' );
update_option( 'blogdescription', 'New Value' );
Hooking on Admin
add_action('admin_init', 'update_my_site_blog_info');
function update_my_site_blog_info() {
$old = get_option('blogdescription');
$new = 'New Site Title';
if ( $old !== $new ) {
update_option( 'blogdescription', $new );
}
}
EDIT:
I guess its better this way,
add_filter('redux/options/[your_opt_name]/compiler', 'update_my_site_blog_info');
function update_my_site_blog_info() {
$new = 'New Site Title';
update_option( 'blogdescription', $new );
}
then your field needs to enabled compiler
array(
'id' => 'blogdescription',
'type' => 'text',
'title' => 'Blog Description',
'default' => '',
'compiler' => true,
),
Thanks for the help, i did like this to make it work.
add_action('init', 'update_my_site_blog_info');
function update_my_site_blog_info()
{
global $opt_keyname;
$check = array('blogdescription', 'blogname');
foreach($check as $key)
{
if ( get_option($key) != $opt_keyname[$key] )
{
update_option( $key, $opt_keyname[$key] );
}
}
}
Redux::setSection( $opt_name,
array(
'title' => 'Basic Settings',
'id' => 'basic_settings',
'fields' => array(
array(
'id' => 'blogname',
'type' => 'text',
'title' => 'Blog Title',
'default' => get_option( 'blogname' )
),
array(
'id' => 'blogdescription',
'type' => 'text',
'title' => 'Blog Description',
'default' => get_option( 'blogdescription' )
),
)
)
);
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 add a category option in my wordpress theme using option tree. I am using this code in theme-option.php
<?php
$categories = get_categories('hide_empty=0&orderby=name');
$wp_cats = array();
foreach ($categories as $category_list ) {
$wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
add_action( 'admin_init', 'custom_theme_options', 1 );
function custom_theme_options() {
$saved_settings = get_option( 'option_tree_settings', array() );
$custom_settings = array(
'sections' => array(
array(
'id' => 'general',
'title' => 'Home Page Settings'
)
),
'settings' => array(
array(
'id' => 'Great-Product',
'label' => 'Great Product',
'desc' => 'select great Product category',
'type' => 'select',
'section' => 'general',
'std' => 'Choose a category',
'options' => $wp_cats
)
)
);
if ( $saved_settings !== $custom_settings ) {
update_option( 'option_tree_settings', $custom_settings );
}
}
?>
But it is not showing any category. Where is my fault? Please tell me.
You need to define $wp_cats variable within your function, or use global to bring it in.
Option 1 (global variable)
<?php
$categories = get_categories('hide_empty=0&orderby=name');
$wp_cats = array();
foreach ($categories as $category_list ) {
$wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
add_action( 'admin_init', 'custom_theme_options', 1 );
function custom_theme_options() {
global $wp_cats; /** GLOBAL!! */
$saved_settings = get_option( 'option_tree_settings', array() );
$custom_settings = array(
'sections' => array(
array(
'id' => 'general',
'title' => 'Home Page Settings'
)
),
'settings' => array(
array(
'id' => 'Great-Product',
'label' => 'Great Product',
'desc' => 'select great Product category',
'type' => 'select',
'section' => 'general',
'std' => 'Choose a category',
'options' => $wp_cats
)
)
);
if ( $saved_settings !== $custom_settings ) {
update_option( 'option_tree_settings', $custom_settings );
}
}
?>
Option 2 (build variable inside function)
<?php
add_action( 'admin_init', 'custom_theme_options', 1 );
function custom_theme_options() {
$categories = get_categories('hide_empty=0&orderby=name');
$wp_cats = array();
foreach ($categories as $category_list ) {
$wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
$saved_settings = get_option( 'option_tree_settings', array() );
$custom_settings = array(
'sections' => array(
array(
'id' => 'general',
'title' => 'Home Page Settings'
)
),
'settings' => array(
array(
'id' => 'Great-Product',
'label' => 'Great Product',
'desc' => 'select great Product category',
'type' => 'select',
'section' => 'general',
'std' => 'Choose a category',
'options' => $wp_cats
)
)
);
if ( $saved_settings !== $custom_settings ) {
update_option( 'option_tree_settings', $custom_settings );
}
}
?>
I have found the solution. Just need to write
'type' => 'category-select',
insted of
'type' => 'select',