Admin Options page. Save as Array

You only need to register one setting and then just modify your form inputs to save the values into an array. Here’s an example of registering the setting: register_setting( ‘mytheme_settings’, ‘mytheme_settings’, ‘admin_options_sanitize’ ); $mytheme_settings = get_option( ‘mytheme_settings’ ); and the field markup: <textarea name=”mytheme_settingsAdmin Options page. Save as Array”> <?php echo esc_textarea( $mytheme_settings[‘title’] ); ?> … Read more

Pass a php string to a javascript variable

You can use the wp_localize_script to pass a variable to your javascript. Here is an example: wp_register_script(‘your_script_name’, ‘path/to/script.js’); $variables = array ( ‘footer_caption’ => $attr[‘footer_caption’], ); wp_localize_script(‘your_script_name’, ‘js_object_name’, $variables ); wp_enqueue_script(‘your_script_name’); Then you can acces to this variable by: js_object_name.footer_caption

Parsing php string in jquery [closed]

Well it seems @JacobPeattie mentioned to use json, I just echoing that. First json encode the variable $array = json_encode($out); Then send this value echo ‘<div data-ad = ‘.$array.’ class=”ash_loadmore”><span>LOAD MORE</span></div>’; To get that echo json_encode($_POST[‘ad’]) I think that’s it.BTW you don’t have now that string problem as the output will be like this {“footer-insta”:2,”sidebar-1″:3} … Read more

How to check the array of featured images IDs

This is solely a PHP question. But as birgire mentioned, you can use in_array(). So, change your code to this: $post_thumbnail_id = get_post_thumbnail_id(); if( in_array( $post_thumbnail_id, array(1, 2, 3 ) ) ) { echo ‘<span>Location</span>’; } The first argument is your value, the second one is the array you want to search in.

var is undefined in a Gutenberg block

I think you have to pass in menu_selected edit: withAPIData( ( props ) => { return { menu_selected: `/menus/v1/menus/${ props.attributes.menu }` // custom endpoint }; } ) ( ( { menu_selected } ) => { I was able to do a very similar thing like so: edit: withAPIData( () => { return { posts: ‘/wp/v2/images?per_page=4&_embed’ … Read more

How to manage arrays from custom functions stored in functions.php?

A callback for an action doesn’t return anything, because that return value is never passed through by WordPress. Use a filter instead: add_filter( ‘listofnames’, ‘SomeNames’ ); function SomeNames() { $names=array( “john”,”edgar”,”miles”); return $names; } And in your template you call it like this: $names = apply_filters( ‘listofnames’, [] ); foreach ( $names a $name ) … Read more

Create a post in custom post type using field in registration form after users submit form

First, add the custom field to the registration form: add_action( ‘register_form’, function(){ ?> <p> <label for=”institute”>Institute</label> <input type=”text” name=”institute” class=”input” value=”” size=”25″> </p> <?php } ); Then, hook to user_register action which gets called after a user has been registered succesfully. add_action(‘user_register’,function($user_id){ $my_institute = array ( ‘post_type’ => ‘Institute’, ‘post_title’ => $_POST[‘institute’], // Custom field … Read more

How to convert objects into arrays

$wpdb->get_results has a second parameter that lets you specify what kind of return value you want: For example: $data = $wpdb->get_results( $query, ARRAY_A ); Here you get an associative array back.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)