WordPress count child posts of each parent custom post type and use in json array for google maps jquery plugin

First of all you should alway separate php from javascript. Generally talking, it’s a bad practise mix them, and specifically to WordPress, it also force you to add javascript inline instead using the WordPress proper way: using wp_enqueue_script. When you need pass variables from PHP to javascript, the proper WordPress way to do it is … Read more

What’s wrong with my date_query?

‘date_query’ argument takes an additional option that is ‘relation’ that can be AND or OR. If we consider the relation OR your code, that use exactly same date for ‘before’ and ‘after’ with ‘inclusive’ set to true, should return all your posts: posts before a date + posts after that date + posts in that … Read more

excluding current post from get_posts

You overwrite the value of $post when you output the first set of posts, so it’s no longer the same post object as your single post. You can either wp_reset_postdata() after each loop (which you should do after the last one anyway), or assign $post->ID to some other var before the loop, and reference that … Read more

Creating a custom search for a specific post type

To enable search on a custom post type archive, I use the pre_get_posts hook. Add this code to your theme functions.php file. Here is an example of enabling search on a post type called “resource”: // Enable resource search add_action(‘pre_get_posts’,’pk_enable_resource_search’, 1000); function pk_enable_resource_search( $query ) { if ( $query->is_archive(‘resource’) && $query->is_main_query() && ! is_admin() ) … Read more

Get specific posts by ID in wordpress

Try this: <?php $thePostIdArray = array(“11”, “13”, “15”, “17”, “19”); $limit = 5; $query=new WP_Query(array(‘post__in’=>$thePostIdArray)); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $counter++; if ( $counter < $limit + 1 ) : $post_id = $thePostIdArray[$counter-1]; $queried_post = get_post($post_id); ?> <a href=”https://wordpress.stackexchange.com/applications”> <div class=”col-md-5 apps text-center”> <?php the_post_thumbnail(‘full’, array( ‘class’ => ‘img-responsive’ … Read more

Get Posts via Taxonomy Term Name with Space

You could get the posts by slug instead of name. Like this: $posts = get_posts(array( ‘post_type’ => ‘coupon’, ‘numberposts’ => -1, ‘post_status’ => array(‘publish’, ‘unreliable’, ‘draft’), ‘tax_query’ => array( array( ‘taxonomy’ => ‘stores’, ‘field’ => ‘slug’, ‘terms’ => array( ‘new-store’ ), ‘include_children’ => false ) ) )); Or you could get the posts by term … Read more

Encrypt / Decrypt Post Title and Details

To change post content before it gets saved you can use wp_insert_post_data filter. I’m using in this example just a simple/dummy way to represent the encryption, I’m just replacing each char with the correspondent ascii code. It should be replaced by your encryption method. add_filter( ‘wp_insert_post_data’ , ‘encrypt_post’ , 99, 1 ); function encrypt_post( $data … Read more

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