If Meta Checkbox is checked, do something?

You’re setting a value whether it’s checked or not with this line: $chk = ( isset( $_POST[‘special_box_check’] ) && $_POST[‘special_box_check’] ) ? ‘on’ : ‘off’; The value is going to be either on or off, so your if condition is always true, since it always has a value. You could change it to save only … Read more

How do I exclude posts by custom field value?

You can use meta query in wp query to get required posts $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘city’, ‘value’ => ‘Melbourne’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘city’, ‘value’ => ‘Melbourne’, ‘compare’ => ‘NOT EXISTS’ ) ) ); $query = new WP_Query( $args );

Is it acceptable to build functionality into a theme built for a client? [closed]

while agreeing 95% with Drew’s answer I would like to attend to another point It’s normally advised to not include custom types or taxonomies in themes as the themes will be less useful to other users, and would not be accepted by the WordPress theme repository. The word of the maintainers of the wordpress.org repository … Read more

Add field to ‘Add User’ admin page

Here’s the way I have always done it. All of this code goes in functions.php. Of course this adds a whole new section to the user profile. add_action( ‘show_user_profile’, ‘be_show_extra_profile_fields’ ); add_action( ‘edit_user_profile’, ‘be_show_extra_profile_fields’ ); function be_show_extra_profile_fields( $user ) { ?> <h3>Extra Contact Information</h3> <table class=”form-table”> <tr> <th><label for=”contact”>Contact Number</label></th> <td> <input type=”text” name=”contact” id=”contact” … Read more

Using more than one meta_key in pre_posts_query

Use WP_Query to select any post based on meta key and value. You can also sort posts Ex: $args = array( ‘post_type’ => ‘events’, ‘orderby’ => ‘meta_value_num’, //probably you will need this because the value is date ‘meta_key’ => ‘event_date’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘event_status’, ‘value’ => $retrieved_status, ‘compare’ => … Read more

How to remove duplicate Custom Fields?

You can delete directly from the database, using an SQL statement like: delete from wp_postmeta where meta_id in ( select * from ( select meta_id from wp_postmeta a where a.meta_key = ‘blogger_blog’ and meta_id not in ( select min(meta_id) from wp_postmeta b where b.post_id = a.post_id and b.meta_key = ‘blogger_blog’ ) ) as x ); … Read more