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.

Defining a global array in functions.php?

In order to access a variable defined in the global scope you must reference it with the global keyword wherever you want to call it again. In your case, the function create_year_terms() must call the global $year_arr within its scope. Also, you can always get your variable in the global scope by using the $GLOBALS … Read more

How to use IN array properly in WordPress?

You need to have your replacement placeholders matching the number of values in your array, and then you can use the array as one of the prepare arguments. Proof of concept: $a = array(‘course_3202′,’course_3201′,’course_3200′,’course_3199′); $b = array_fill(0,count($a),’%s’); $b = implode(‘,’,$b); $sql = “SELECT * FROM $wpdb->postmeta”; $sql .= ” WHERE meta_key IN ({$b}) and meta_value=1″; … Read more

Must Use Plugin Causing Query Error

As Milo ( and your errors ) point out: you’re passing an array where a string is expected. According to WP_Query tag parameter Show posts associated with certain tags. tag (string) – use tag slug. To get around this you just need to pass a comma separated string: function custom_tags( $query ) { $query->set( ‘tag’, … Read more

WP Job Manager Category Drop-down; Change Placeholder Text Via Filter

Based on the testing that I did, the placeholder string Choose a category… cannot be filtered with the submit_job_form_fields filter, but there are still ways to change that string. One way to alter the text is to override the plugin’s default job-filters.php template with your own. Copy the default template, /wp-job-manager/templates/job-filters.php over to your theme: … Read more