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

single page wordpress

There’s nothing stopping you using AJAX for a singlepage website that loads in other pages dynamically rather than going to a whole new page. I would advise you build the site without the AJAX and then add AJAX on top so that everything degrades gracefully should an error occur or if javascript is turned off. … Read more

Custom SQL query to get List of posts with featured image url

Worked on similar problem recently. Here is the SQL query to get the post with Featured Image. global $wpdb; $perpage = 10; $page = 1; // Get the current page FROM $wp_query $counter = $perpage * $page; $uploadDir = wp_upload_dir(); $uploadDir = $uploadDir[‘baseurl’]; $sql = ” SELECT post.ID, post.post_title, post.post_date, post.category_name, post.category_slug, post.category_id, CONCAT( ‘”.$uploadDir.”‘,”https://wordpress.stackexchange.com/”, … Read more

Pull Two Posts Into Custom Post Type `single-cpt.php`

Try this: <?php $current_id = get_the_ID(); $next_post = get_next_post(); $next_id = $next_post->ID; $cpt = get_post_type(); $cpt_array = array($current_id, $next_id); $args = array( ‘post_type’ => $cpt, ‘post__in’ => $cpt_array, ‘order_by’ => ‘post_date’, ‘order’ => ‘ASC’, ); $the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts() ): $the_query->the_post(); echo ‘<h2>’.the_title().'</h2>’; endwhile; endif; wp_reset_postdata(); ?> Tested locally and seems to work … Read more

Listing a post’s categories and subcategories

Update 1: Thanks to @birgire for suggesting a better way: wp_list_categories( [ ‘include’ => wp_list_pluck( get_the_category(), ‘term_id’ ) ] ); Try this in your single.php template: $current_cats = get_the_category(); $current_cats_ids = []; foreach ($current_cats as $cat) { $current_cats_ids[] = $cat->term_id; } wp_list_categories([ ‘include’ => $current_cats_ids, ]);

Pre get posts for single post

First of all, $query object is passed by reference, you don’t need to return $query in pre_get_posts. Second, is_post_type_archive( ‘events’ ) will work just fine, you don’t need to use query->query_vars[]. Corrected code will look like this: function my_pre_get_posts( $query ) { if( ! is_admin() && is_main_query() && is_post_type_archive( ‘events’ ) ) { $query->set(‘orderby’, ‘meta_value_num’); … Read more

Posts in multiple Categories different single.php

Instead of making it category specific you could use post formats and use different content-templates. In single.php you can write <?php get_template_part( ‘content’, get_post_format() ); ?> Then create different post formats add_theme_support( ‘post-formats’, array( ‘withpictures’, ‘withcomments’ ) ); Then create different post templates content-withpictures.php, content-withcomments.php When creating content the chosen post format will determine the … Read more

How do I create a link that will always show the latest post?

If I understand well you want to show the last post (one post) from one of the 3 post types you have, using a dynamic url like http://example.com/latest. First of all lets add a filter to ‘do_parse_request’ filter: add_filter( ‘do_parse_request’, function( $bool, WP $wp ) { $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), “https://wordpress.stackexchange.com/” ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)