Pre-filling custom fields on New Post

Here’s one way to have a custom field, already added and visible, for new posts: /** * Preset a custom field for new posts * * @link http://wordpress.stackexchange.com/a/200554/26350 */ add_action( ‘save_post_post’, function( $post_ID, $post, $update ) { if( is_a( $post, ‘\WP_Post’ ) && ‘auto-draft’ === $post->post_status && post_type_supports( $post->post_type, ‘custom-fields’ ) && ‘0000-00-00 00:00:00’ === … Read more

Meta Query with AND & OR?

Sorry, doesn’t work that way. The “simple” meta parameters are converted into part of the meta_query as a whole. So it’s not a separate thing, and your OR relation applies to it as well. Your query thus is not possible with the normal query system, because you want to mix ANDs with ORs (you want … Read more

Extra profile field as select box?

Place the following code in your functions.php <?php add_action( ‘show_user_profile’, ‘show_extra_profile_fields’ ); add_action( ‘edit_user_profile’, ‘show_extra_profile_fields’ ); function show_extra_profile_fields( $user ) { ?> <h3>Extra profile information</h3> <table class=”form-table”> <tr> <th><label for=”gender”>Gender</label></th> <td> <select name=”gender” id=”gender” > <option value=”Male” <?php selected( ‘Male’, get_the_author_meta( ‘gender’, $user->ID ) ); ?>>Male</option> <option value=”Female” <?php selected( ‘Female’, get_the_author_meta( ‘gender’, $user->ID ) … Read more

Filter post listing by meta value which is a date

Add a query variable to store the month So first of all it’ll be necessary to create a custom query variable – this will store the month we’re after (in 2012/6) format. I’ll call it custom_month, but its best practise to prefix it to avoid clashes with other plug-ins: add_filter(‘query_vars’, ‘wpse57344_register_query_vars’ ); function wpse57344_register_query_vars( $qvars … Read more

Apply the_content filter to a custom field with multiple values

All you need to do use apply_filters. foreach ($video as $vid) { echo ‘<li>’.apply_filters(‘the_content’,$vid).'</li>’; } It may be more efficient to concatenate a string and then run the filter on the whole thing. $lis=””; foreach ($video as $vid) { $lis .= ‘<li>’.$vid.'</li>’; } echo apply_filters(‘the_content’,$lis); I haven’t benchmarked the one versus the other but given … Read more

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