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
));
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
I am using wordpress and 2 plugins called unyson and brizy.
Basically unyson provides me a shortcode I want to call trough the front page builder brizy on my homepage.
I want to call the portfolio shortcode with [portfolio]
This works.
Live website: https://xprs.ch/
Under "Our Work Portfolio"
Now I want to add options:
[portfolio page_link="On" categories="website"]
As long as I just define page_link it works.
But as soon as I try to define the categories I get the following error:
Warning: in_array() expects parameter 2 to be array, string given in /home/httpd/vhosts/xprs.ch/httpdocs/wp-content/themes/jevelin/framework-customizations/extensions/shortcodes/shortcodes/portfolio/views/view.php on line 100
I also get above error if just defining categories so I need to define this different but how?
The code from the shortcode:
NOTE: I cannot change this code.
I need to pass the parameter "website" correctly in the front end.
$options = array(
'id' => array( 'type' => 'unique' ),
'general' => array(
'title' => esc_html__( 'General', 'jevelin' ),
'type' => 'tab',
'options' => array(
'style' => array(
'type' => 'radio',
'label' => esc_html__('Style', 'jevelin'),
'desc' => esc_html__('Choose main style', 'jevelin'),
'choices' => array(
'default' => esc_html__('Standard', 'jevelin'),
'default-shadow' => esc_html__('Standard with Shadow', 'jevelin'),
'default2' => esc_html__('Trendy', 'jevelin'),
'masonry' => esc_html__('Gallery', 'jevelin'),
'masonry2' => esc_html__('Marginless Gallery', 'jevelin'),
'minimalistic' => esc_html__('Minimalistic', 'jevelin'),
),
'value' => 'default',
),
'categories' => array(
'type' => 'multi-select',
'label' => esc_html__('Categories', 'jevelin'),
'desc' => esc_html__('Select categories', 'jevelin'),
'population' => 'taxonomy',
'source' => 'fw-portfolio-category',
'prepopulate' => 200,
'limit' => 100,
),
'page_link' => array(
'type' => 'switch',
'label' => esc_html__( 'Page Link', 'jevelin' ),
'desc' => esc_html__( 'Enable or disable portfolio page link', 'jevelin' ),
'value' => true,
'left-choice' => array(
'value' => false,
'label' => esc_html__('Off', 'jevelin'),
),
'right-choice' => array(
'value' => true,
'label' => esc_html__('On', 'jevelin'),
),
),
),
),
);
How do I need to call categories?
Here:
$cats = array();
foreach( get_the_category() as $cat ) {
$cats[] = $cat->cat_ID;
}
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $cats,
'include_children' => false
)
)
);
print_r( WP_Query( $args ) as $post );
http://codex.wordpress.org/Class_Reference/WP_Query
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,
) );
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>';
}
?>
am working on a wordpress admin panel using startbox admin panel, where I want to list all categories with slug and name inside an array but it seems impossible for me to make it work, here is my code
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
// This much above code is given by wordpress to get all categories, mine starts below
class sb_slider_settings extends sb_settings {
function sb_slider_settings() {
$this->slug = 'sb_slider_settings';
$this->options = array(
'on_off_news' => array(
'type' => 'select',
'default' => 'true',
'label' => __( 'Enable breaking news', 'startbox' ),
'options' => array(
'false' => __( 'No', 'startbox' ),
'true' => __( 'Yes', 'startbox' ),
)
),
'ticker_text' => array(
'type' => 'select',
'default' => 'true',
'class' => 'ticker_text',
'label' => __( 'Extract posts from', 'startbox' ),
'options' => array(
foreach($categories as $category) {
$category->slug => __( $category->name , 'startbox' ) ;
}
)
)
);
parent::__construct();
}
}
Error it shows,
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'
However you can user array_map to call same function on each element of an array :
http://us1.php.net/manual/fr/function.array-map.php
In your case,
'options' => array_map('callback', $categories),
and your callback
function callback($category) {
return __( $category->name , 'startbox' );
);
You can't execute code inside an array. An array is intended to have fixed values in it.
http://es1.php.net/manual/en/language.types.array.php
To do what you wanna do you must create a function and call that function inside your array.