Getting post content without the navigation

the_content() will output the formatted post to the web browser, if the tag is used in the post it will only display the post up to this point and will out put a “Read More” link. There are some additional flags in the method to control this behaviour. See more here. Alternatively, you may load … Read more

how can I add data to posts that can be retrieved by WP Rest API

The WP API has hooks, like rest_prepare_page to enhance the endpoints. For each post type give it different hooks the follow code example add the tags to post and page and illustrate, how it works. /** * Add properties to posts and pages endpoints. */function wp_api_theming_posts_properties( $response ) { // Set author’s name. $author = … Read more

get current post id inside hook

The new_to_publish hook has one argument: $post. Use that to get the post id. Here is your editted code: add_action( ‘new_to_publish’, ‘send_notification’, 1, 1 ); function send_notification( $post ){ $post_id = $post->ID;; global $wpdb; $sel2 = mysql_query(“select * from gcm_users”); while($data1 = mysql_fetch_assoc($sel2)) { $key = $data1[‘gcm_regid’]; include_once ‘../blogdroid/config.php’; include_once ‘../blogdroid/GCM.php’; $gcm = new GCM(); … Read more

Custom post preview without saving

I found a nice way to do this using the preview_post_link filter, which allows you to rewrite the URL used by the preview operation. In my case I did something like: add_filter( ‘preview_post_link’, function ( $link ) { return ‘http://domain.com/mobile-preview/?src=”https://wordpress.stackexchange.com/questions/191918/. urlencode($link) .”%26admin_bar=false’; } ); When I click my preview button WordPress opens up my custom … Read more

Display Published Posts Count for Certain Time Period

You can fetch the record using bellow query $posts= get_posts(array( ‘numberposts’ => -1, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘date_query’ => array( ‘column’ => ‘post_date’, ‘after’ => ‘-7 days’ // -7 Means last 7 days ) )); echo count($posts); If you want to get last 6 month the use -6 Months

WP Query to Get Array of Slugs

Just run a normal tax_query and set the field parameter to slug in the query. I assume that you already have a way getting the array of slugs (Requires PHP5.4+) $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘tax_query’ => [ [ ‘taxonomy’ => ‘TAXONOMY_NAME’, ‘field’ => ‘slug’, ‘terms’ => [‘something’, ‘something-again’, ‘something-else’], ] … Read more

Get Posts that are in the current month or later

You can use meta_query, if you date information is saved in custom field. Like this: $args = array( ‘post_type’ => $custom_post_type, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘event_date_and_time’, ‘value’ => current_time(‘Ymd’), ‘compare’ => ‘>=’ ) ), ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ); This code suppose you date is saved in YYYYMMDD … Read more

Counter of posts ever posted – even deleted ones

Depending on your needs, WP Query may not work for this since it won’t include posts that have been deleted after the trash has been emptied. This should work (but hasn’t been tested): function wpse_custom_post_type_counter() { $number = get_option( ‘wpse_custom_counter’ ) ? absint( get_option( ‘wpse_custom_counter’ ) ): 0; $number++; update_option( ‘wpse_custom_counter’, $number ); } add_action( … Read more