Autoprediction / Autocomplete Search with Meta Keys

If you want to show custom field values, you can’t use WP_Query that select posts. It seems to me that the only available way is to write a sql query and execute it in $wpdb. global $wpdb; if ( isset($_POST[‘search’]) == false || empty($_POST[‘search’]) ) wp_send_json_success( $array() ); $s = $_POST[‘search’]; $meta_keys = [‘PLZ’, ‘ort’, … Read more

Add a default meta_value to new posts

Add this to your functions.php in your template folder. <?php //Set Default Meta Value function set_default_meta_new_post($post_ID){ $current_field_value = get_post_meta($post_ID,’YOURMETAKEY’,true); //change YOUMETAKEY to a default $default_meta=”100″; //set default value if ($current_field_value == ” && !wp_is_post_revision($post_ID)){ add_post_meta($post_ID,’YOURMETAKEY’,$default_meta,true); } return $post_ID; } add_action(‘wp_insert_post’,’set_default_meta_new_post’); ?>

WP_query : meta_key with custom rule for specific value

A meta_query is an array of arrays. Look at the examples in the the Codex. $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array(3, 4), ‘compare’ => ‘IN’, ) ) ); $query = new WP_Query($args); What you have is … Read more

Sorting meta_value as integer doesn’t work

It’s not the plugin that is causing the issue it is the fact you are not querying the database correctly. It is not looking for integers your value is currently being stored as a string. To fix this you need to somehow change the value to a integer before it is passed to your array.

Using get_terms() with meta_query parameters

Inserting boolean term meta values When we add non-existent term meta with e.g. add_term_meta( 123, ‘test’, true ); then we are actually running the following insert : $wpdb->insert( ‘wp_termmeta’, array( ‘term_id’ => 123, ‘meta_key’ => ‘test’, ‘meta_value’ => true ) ); within the general add_metadata() function. Now wpdb::insert() is actually a wrapper for wpdb::_insert_replace_helper() that … Read more

Help With issue on pre_get_posts filter in taxonomy

Solved! I was using the wrong technique to create a custom query to my taxonomy instead of using the function above I create new function that use query_vars. Here is the code function taxonomy_posts_order($query) { global $browsetype; $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); if ( $query->query_vars[‘taxonomy’] == $term->slug ) { … Read more

Order by custom field date with ASC order

With some more googling: <?php $today = date(“Y/m/j”); query_posts(array( ‘post_type’ => ‘custompost’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘mydate’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘mydate’, ‘meta-value’ => $value, ‘value’ => $today, ‘compare’ => ‘>=’, ‘type’ => ‘CHAR’ ) ) )); if (have_posts()) : while (have_posts()) : the_post(); ?> <a … Read more

Multiple Values stored as array in Meta Query

An IN query is not a string comparison query. It is more like a bunch of OR statements. … WHERE tablename.animal IN (‘cat’,’dog’,’ferret’) is going to be the same as …WHERE tablename.animal=”cat” OR tablename.animal=”dog” OR tablename.animal=”ferret” $_POST[‘_casestudypost’] is going to be an array, and if you stored it as a single value in postmeta it … Read more

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