Disable Single Post View for Specific Taxonomy on Custom Post Type

I use template_redirect hook for this purpose. I suppose rented in your question is not taxonomy itself, but one term of some taxonomy. function my_page_template_redirect() { if( is_singular( ‘rentals’ ) && has_term(‘rented’, ‘your taxonomy name’) ) { wp_redirect( home_url(), 301 ); exit(); } } add_action( ‘template_redirect’, ‘my_page_template_redirect’ ); Before page rendering, WP checks if CPT … Read more

Post being redirected to attachment post

I think the reason for this is the get_page_by_path() check inside the WP_Query, because it’s checking for both page and attachment slugs, in this case. So if we have both an attachment and a post with the someslug postname and visit: example.tdl/someslug then get_page_by_path() will generate the following query: SELECT ID, post_name, post_parent, post_type FROM … Read more

WordPress plugin how to run function when button is clicked

Create form or link with action=”my_media_update” <form action=”<?php echo admin_url(‘admin-post.php’); ?>” method=”post”> <input type=”hidden” name=”action” value=”my_media_update”> <input type=”submit” value=”Update Media Titles and ALT Text”> </form> Add this function and hook in your plugin file: public function kh_update_media_seo() { //update media files title and alt tags here // // at the end redirect to target page … Read more

How to remove the index.php in the url?

The problem likely has to do with the server settings in Nginx for your blog. It’s likely that the location rules for /blog/ are wrong, specifically try_files. It should look like this: location /blog/ { try_files $uri $uri/ /index.php$is_args$args; } This tells Nginx the order in which it should try to find the requested resource. … Read more

If permalink is equal to current site url

I would do something simplier using ID : <?php $current_id = $post->ID; ?> <?php query_posts(‘orderby=name’); ?> <?php while (have_posts()) : the_post(); ?> <li> <?php $current_class = ( $current_id == $post->ID ) ? ‘class=”current”‘ : ”; ?> <a <?php if ( $current_class ) echo $current_class; ?> href=”https://wordpress.stackexchange.com/questions/88833/<?php the_permalink() ?>”> <?php the_title() ?> </a> </li> <?php endwhile; … Read more

Facebook Comment Count

Final version of code used: function fb_comment_count($link = ‘link’) { global $post; $url=”https://graph.facebook.com/”; $posturl = get_permalink($post->ID); $url .= $posturl; $filecontent = wp_remote_retrieve_body(wp_remote_get($url, array(‘sslverify’=>false))); $json = json_decode($filecontent); $count = $json->comments; if ($count == 0 || !isset($count)) { $count = 0; } $comments = $count; if ($count == 1) { $comments .= ‘ Comment’; } elseif ($count … Read more