I can get wordpress page list to elementor selector. I can get the pages as a list, but the title field remains as the page id. can someone help
$options = array();
$pages = get_pages(array(
));
foreach ($pages as $key => $page) {
$options[$page->ID] = get_the_title($page->ID);
}
$repeater = new \Elementor\Repeater();
$repeater->add_control(
'selected_item_id',
[
'label' => __('Portfolio Item', 'cabei'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $options,
]
);
$this->add_control(
'list',
[
'label' => esc_html__( 'Repeater List', 'cabei' ),
'type' => \Elementor\Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'title_field' => '{{{ selected_item_id }}}',
]
);
title field display page id :
Related
// adding category select to the customizer
//Get an array with the category list
$silicon_cac_full_list = get_categories(array( 'orderby' => 'name', ));
//Create an empty array
$silicon_cac_list = [];
//Loop through the array and add the correct values every time
foreach( $silicon_cac_full_list as $silicon_single_cat ) {
$silicon_cac_list[$silicon_single_cat->slug] = esc_html__( $silicon_single_cat->name, 'silicon' );
}
$wp_customize-> add_section('silicon_category_post_sec', array(
'title' => __('Category','silicon'),
'description' => __('Category you select here will be displayed in featured area','silicon')
));
$wp_customize-> add_setting('silicon_category_post_set', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 'uncategorized',
));
$wp_customize-> add_control( 'silicon_category_post_ctrl', array(
'label' => __('Category','silicon'),
'description' => __('Category you select here will be displayed in featured area','silicon'),
'section' => 'silicon_featured_post_sec',
'settings' => 'silicon_featured_post_set',
'type' => 'select',
'choices' => $silicon_cac_list,
));
I wanted to show posts by the category I selected in the customizer. But the problem is it is showing all posts. Even after selecting any category.
My control code is
i want to create control in elementor which shows all post categories. please help me how can i achieve this...
enter image description here
$this->add_control(
'show_elements',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => [
$category,
],
]
); ```
You can use WP get_categories() to get all categories. check below code.
$options = array();
$args = array(
'hide_empty' => false,
);
$categories = get_categories($args);
foreach ( $categories as $key => $category ) {
$options[$category->term_id] = $category->name;
}
$this->add_control(
'show_elements',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => $options,
]
);
I am trying to update a products custom taxonomy term via the wp-json api.
I have added the below function to handle taxonomies:
function wp_api_add_tax($post, $data, $update){
foreach( $data['custom_tax'] as $tax => $val ){
wp_set_post_terms( $post['ID'], $val, $tax );
}
}
add_filter('json_insert_post', 'wp_api_add_tax', 10, 3);
And then add then taxonomy term like this:
$api_response = wp_remote_post( 'https://example.com/wp-json/wc/v2/products/4286', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'xxxxxxxxxxxx:xxxxxxxxxx' )
),
'body' => array(
'stock_quantity' => '0',
'categories' => array(
array(
'id' => 373
),
array(
'name' => 'Build Lean Muscle'
)
),
'custom_tax' => array(
'My Taxonomy Here' => 'My Term Here'
),
'meta_data' => array(
array(
'key' => 'nutritional',
'value' => 'nutritional description by the api 2'
)
)
)
) );
Is this the correct way of doing things? The custom taxonomy term does not get updated.
I just want to add a custom field in the product category page in admin using the metabox plugin https://metabox.io/
This is in woocommerce and this is what I have
add_filter( 'rwmb_meta_boxes', 'product_register_meta_boxes' );
function product_register_meta_boxes( $meta_boxes )
{
$prefix = 'product_';
$meta_boxes[] = array(
'id' => 'product_cat_keywords_search',
'title' => __( 'Searchable keywords', 'your-prefix' ),
'post_types' => array( 'product'),
'taxonomy' => array( 'product_cat'),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'name' => __( 'Product Category Keywords', 'your-prefix' ),
'id' => "{$prefix}pcat_keywords",
'desc' => __( 'Category Keywords', 'your-prefix' ),
'type' => 'text',
'std' => __( '', 'your-prefix' ),
'clone' => true,
'clone-group' => 'my-clone-group2',
),
)
);
return $meta_boxes;
}
This code only appears in product page and not in product category page.
I need to use metabox since I will be using the clone feature, thanks
Adding OptionTree pages is simple with the code below, but does anyone know how to retrieve the stored data?
/**
* Hook to register admin pages
*/
add_action( 'init', 'register_options_pages' );
/**
* Registers all the required admin pages.
*/
function register_options_pages() {
// Only execute in admin & if OT is installed
if ( is_admin() && function_exists( 'ot_register_settings' ) ) {
// Register the pages
ot_register_settings(
array(
array(
'id' => 'custom_options',
'pages' => array(
array(
'id' => 'test_page',
'parent_slug' => 'options-general.php',
'page_title' => 'Test Page',
'menu_title' => 'Test Page',
'capability' => 'edit_theme_options',
'menu_slug' => 'test-page',
'icon_url' => null,
'position' => null,
'updated_message' => 'Test Page updated.',
'reset_message' => 'Test Page reset.',
'button_text' => 'Save Changes',
'show_buttons' => true,
'screen_icon' => 'options-general',
'contextual_help' => null,
'sections' => array(
array(
'id' => 'test_section',
'title' => __( 'Test Section', 'motif-core' )
)
),
'settings' => array(
array(
'id' => 'test_section_input',
'label' => 'Test Input',
'desc' => 'Pretty freaking awesome!',
'std' => '',
'type' => 'text',
'section' => 'test_section',
'class' => ''
)
)
)
)
)
)
);
I tried this $my_plugin_options = get_option('custom_options'); but it only shows the word 'array' on the front end?
This is how to retrieve the stored data:
$my_plugin_options = get_option('custom_options');
echo $my_plugin_options['test_section_input'];