Sorting posts by custom fields in meta_query

As of WordPress 4.2, you can combine meta_query and orderby. The following example is taken from make.wordpress.org. Example of a simple meta_query: $q = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘state_clause’ => array( ‘key’ => ‘state’, ‘value’ => ‘Wisconsin’, ), ‘city_clause’ => array( ‘key’ => ‘city’, ‘compare’ => ‘EXISTS’, ), ), ‘orderby’ … Read more

Escaping Quotes

WordPress emulates magic_quotes_gpc and won’t be deprecating this for some time due to concerns over plugin security and backward compatibility. To work around this, you need to use stripslashes() or, if you need to strip slashes when data arrives via $_POST, $_GET, $_COOKIE, and $_REQUEST arrays, you can use the WordPress stripslashes_deep() function: http://codex.wordpress.org/Function_Reference/stripslashes_deep

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 );

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

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