Display custom post types by date field

I solved the same problem like this First you store each posts in another array called $events_by_date with date as the index. If another event post falls in the same date you put that post under the same index. Please comment if you need further explanation. <?php //setup your wp_query parmeters to make the query … Read more

Custom wp_trim_words() function not trimming right

What about using this function in functions.php: function new_excerpt_length($length) { return 20; } add_filter(‘excerpt_length’, ‘new_excerpt_length’); And then getting it by adding<?php the_excerpt()?> to php template? OR: <?php $string = get_the_excerpt(); if (strlen($string) <=20) {echo ” . $string . ”;} else {echo ” . substr($string, 0, 20) . ‘…’;}?> In this case 20 is characters

How to search only by post title and category?

You’ll have to write a custom WP_Query in search.php. Also since you want to search in post_title + categories, you might have to run 2 separate queries and merge results of them into 1. Something like: $q1 = get_posts(array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ‘-1’, ‘s’ => get_search_query() )); $q2 = get_posts(array( … Read more

How to display related posts from parent category

Just change this one line: $cat_obj = $wp_query->get_queried_object(); $thiscat_id = $cat_obj->term_id; $thiscat = get_category($thiscat_id); $chi = array(); if (!empty($thiscat->parent)) { $parentcat = get_category($thiscat->parent); $categories_chi=get_categories( array( ‘parent’ => $parentcat->cat_ID ) ); foreach ($categories_chi as $key => $value) { $chi[] = $value->cat_ID; } $pare = array($parentcat->term_id); $ids = array_merge($pare, $chi); } else { $ids = array($cat_obj->term_id); } … Read more

why does HTML Tag not working in Post and Page

[*] It’s not the theme that’s how TinyMCE editor works. If you remain on the “Text” tab and update the post then the html will remain untouched and display properly on the front-end. However if you switch back to the “visual editor” it will break. Here, you can use this on your functions.php // Modify … Read more

Order post by year DESC and month ASC

To show a list by Year DESC and by month ASC: change your post type with custom_post. global $wpdb; $posts = $wpdb->posts; $sql = “SELECT DISTINCT(YEAR(`post_date`)) as years FROM $posts WHERE post_type=”custom_post” ORDER BY years DESC”; //Get all post year list by DESC $result = $wpdb->get_results($sql); foreach($result as $rs) { echo ‘<h2>’.$rs->years.'</h2>’; $args = array( … Read more