Why is my Blog Page ID == First Post ID?

the ‘posts page’ ID when using a static front page and a different posts page is: get_option( ‘page_for_posts’ ) in some context: if( is_home() && get_option( ‘page_for_posts’ ) ) { $page_ID = get_option( ‘page_for_posts’ ); }

custom post scheduler for drafts

You’re treating $my_post as an array, and then an object. Try moving ‘edit_date’ into the array. Also keep in mind that ‘post_date’ should be in your blog’s timezone. date will give the date-time in UTC timezone. See date_i18n() (codex: http://codex.wordpress.org/Function_Reference/date_i18n). From what I can see, everything else is corret.

How to give capability (publish contributors posts) to author role?

I think that the best approach is to add the edit_other_posts capability to “author” role in plugin/theme activation and remove that capability on plugin/theme deactivation. With this method you only run the task once and you don’t need further coding. Using plugin activation/deactivation: register_activation_hook( __FILE__, ‘cyb_activation_function’ ); function cyb_activation_function() { $author = get_role( ‘author’ ); … Read more

do_shortcode within post query

You set $post_slug outside the Loop, so the value never changes. You need to reset that inside the Loop so that it will be reset to each post in turn as the Loop progresses. $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $post_slug = $post->post_name; echo … Read more

open selected wordpress post with javascript

You could use the following: <script> function open_win( thePostURL ) { window.open(thePostURL); } </script> <a href=”#” onclick=”open_win( “https://wordpress.stackexchange.com/questions/116036/<?php the_permalink(); ?>” )”>More…</a> It seems like a bit more work than it’s worth though, the following would have the same result of the link opening in a new window: <a href=”https://wordpress.stackexchange.com/questions/116036/<?php the_permalink(); ?>” target=”_blank”>More…</a>

Sticky post appears twice

What you describe is not an issue but normal WordPress behaviour. When you mark a post as a sticky it will be at the top of the list and it will appear in it’s original postition as well, unless the original position is on the first page. A sticky will appear at the top of … Read more

Post-ID in url differs from $post->ID

There are two ways to get what you need. One is mentioned in Identify the page being shown while in The Loop: $post_id = get_queried_object_id(); Unfortunately, this might break. get_queried_object_id() looks in the global variable $wp_query for the ID, and that variable can be overwritten during the page rendering by query_posts(). The same is true … Read more

How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?

Intercept the query on the posts_where filter. In there you can do a replacement of the non numeric values: preg_replace( “/[^0-9,.]/”, “”, $yourMeta ); Or in a (generic) code piece: add_action( ‘posts_where’, ‘wpse120784WhereDiameter’, 100 ); function wpse120784WhereDiameter( $where ) { // If conditions here – only target the cases where we need it # if … Read more