Creating an empty page programatically

Add a post meta field to indicate this post is just a redirect when creating it: $postid = wp_insert_post($newpost); add_post_meta($postid,’redirect’,’1′); Check the post meta value and if it is a “redirect post”, just output the post content (javascript redirect): add_action(‘wp’,’custom_maybe_redirect’); function custom_maybe_redirect(); global $post; if (!is_object($post)) {return;} $redirect = get_post_meta($post->ID,’redirect’,true); if ($redirect == ‘1’) {echo … Read more

Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?

I think you are looking for this- function star_rating( $atts ) { $max = 5; $atts = shortcode_atts( array( ‘grade’ => $max, // default ), $atts ); $star_icons=””; $full_star = floor( $atts[‘grade’] ); for( $i=1; $i<=$full_star; $i++ ) { $star_icons .= ‘<i class=”fa fa-star”></i>’; } $half_star = 0; if( (int) $atts[‘grade’] != $atts[‘grade’] ){ $half_star … Read more

After plugin activation hook

In the context of official plugin repository this is very explicitly forbidden by the guidelines (emphasis mine): 7. No “phoning home” without user’s informed consent. This seemingly simple rule actually covers several different aspects: No unauthorized collection of user data. For example, sending the admin’s email address back to your own servers without permission of … Read more

How to get all posts belongs to a user between a certain date

Check out the WP_Query reference. For parameters. Date Parameters. $args = array( ‘author’ => 123 , ‘date_query’ => array( array( ‘after’ => ‘January 1st, 2013’, ‘before’ => array( ‘year’ => 2013, ‘month’ => 2, ‘day’ => 28, ), ‘inclusive’ => true, ), ), ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); For the … Read more

Problem with AJAX in wordpress plugin

After Milo’s tutorship: I recommend first reading how to use AJAX in Plugins properly. – Milo yesterday and reading another questions on wp.stack, my problem was solved) Here is an examples of code from my rewritten files 1)get_state.php: ad add_action( ‘wp_ajax_ajax_object’, ‘ajax_handler’ ); add_action( ‘wp_ajax_nopriv_ajax_object’, ‘ajax_handler’ ); function ajax_handler() { global $wpdb, $results, $info, $data, … Read more