Retain select value in select box

If I have understood correctly, you could use get_the_ID() and compare the value with get_queried_object_id() to archive this: $args = array( ‘post_type’=> ‘portfolio’, ‘posts_per_page’ =>100, ‘offset’=> 0 ); $myposts = get_posts( $args ); $current_id = get_queried_object_id(); foreach ( $myposts as $post ) { setup_postdata( $post ); printf( ‘<option%s>%s</option>’, ( $current_id == get_the_ID() ) ? ‘ … Read more

URL Rewriting if it is a single post / redirecting post – post type

First of all set your permalink structure to /%postname%. After that add a rewrite rule to rewrite all request like example.com/blog/postname to the appropriate query: add_action(‘init’, ‘blog_front’); function blog_front() { add_rewrite_rule(‘^blog/([^/]+)/?’,’index.php?name=$matches[1]’,’top’); } Now you have to prevent the duplicate url, sending a 301 redirect when example.com/postname is requested: add_action(‘template_redirect’, ‘say_hello_to_google’); function say_hello_to_google() { if ( … Read more

How to hide first gallery for every post?

You could use preg_replace() but I think it’s much easier to overwrite the $output via the post_gallery filter and then remove the filter after the first run: /** * Remove the output of the first gallery * * @param string $output * @param array $attr * @return string $output */ function wpse125903_remove_the_first_gallery( $output, $attr ) … Read more

Execute a plugin only on post pages

No, the plugin is loaded long before WordPress has figured out if it should display a single post. But you can restrict the code of the plugin to do something only then. Example: add_action( ‘template_redirect’, function() { if ( ! is_single() ) return; // initialize plugin code here. });

Post Filter by Date and time

Try to use new WP_Query for this. Add a new query and pass below argument. $args = array( ‘date_query’ => array( array( ‘after’ => ‘2014-02-01’, ‘before’ => ‘2014-02-07’, ‘inclusive’ => true, ), ), ); $my_query = new WP_Query( $args );