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

Working with an Array inside Your Theme Options Array – Multiple Values

Assuming this array for example usage: $options = array( “name” => __(‘Font’,’mytheme’), “desc” => __(‘Change the font face)’,’mytheme’), “id” => “mytheme_font”, “std” => array(‘size’ => ’10px’, ‘face’ => ‘Arial’, ‘color’ => ‘#000000’), “type” => “text”, ); For question 1, to reference nested arrays, just reference them directly. echo $options[‘std’][‘size’]; In the form input, if using … Read more

how to store arrays into a database

What WP does for arrays (and objects) on some contexts (such as post fields) is using maybe_serialize()/maybe_unserialize() to turn such types (and just them) to and from serialized (string-typed) representation. While this simplifies workflow it comes with penalties, such as being unable to properly query through such data and common issues with migration (seriazlization-unaware tools … Read more