Querying a custom post type, but not show duplicates

Ahh iv figured out a way to do this: <?php $args = array( ‘post_type’ => ‘classes’, ‘orderby’ => ‘title’, ‘posts_per_page’ => -1 ); $the_query = new WP_Query( $args ); $unique_titles = array(); if( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $title = get_the_title(); if( ! in_array( $title, $unique_cities ) ) : $unique_titles[] = … Read more

post_content is stripping HTML when adding a new post? [closed]

When WP inserts a post one of the things it does is check both the current user’s capabilities, and which html tags are allowed to be used. There are two ways to modify this: Method 1: wp_kses_allowed_html hook You can modify the allowed set of html tags, given a context, by using this filter: https://codex.wordpress.org/Function_Reference/wp_kses_allowed_html … Read more

not showing custom type meta box

Try below code. add_action(‘add_meta_boxes’,’create_events_metaboxes’); function create_events_metaboxes() { add_meta_box(‘events-meta-box’,’Events Details’,’show_events_metaboxes’,’events-lists’); } function show_events_metaboxes($post){ echo ‘Hello Meta box’; } Hope this will helps you. Refer from add_meta_box

How to determine next custom post in hierarchy

Here I’ve written a SQL based function for you- function the_dramatist_get_last_post($current_post_type=”viz”, $other_post_type=”portfolio”, $post_id = ”, $prev = true) { global $wpdb; $order_by = $prev ? ‘ASC’ : ‘DESC’; $sign = $prev ? ‘<‘ : ‘>’; $sql = $wpdb->prepare(“SELECT * FROM {$wpdb->posts} AS p WHERE p.post_type != %s AND p.post_type LIKE %s AND p.id {$sign} %d … Read more

How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit

You can count the number of words in your text to check if it’s greater than 15 using the str_word_count php function, and if not return your read more link also So i would modify your custom field excerpt thus: function custom_field_excerpt() { global $post; $text = get_field(‘description’); if (” != $text) { $text = … Read more

WordPress custom post categories and subcategories on category.php

Thanks to all! Here is my solution which worknig well <?php $cat = get_query_var(‘cat’); $categories = get_categories(‘parent=”.$cat.”‘); if(isset($categories) && !empty($categories)){ foreach ($categories as $category) { ?> <span class=”subhead-title”><?php echo $category->name; ?></span> <?php $prods = new WP_query(); $prods->query(‘post_type=products&cat=” . $category->cat_ID . “‘); ?> <?php if($prods->have_posts()) { ?> <ul class=”cat-arc-links”> <?php while ($prods->have_posts()) { $prods->the_post(); ?> <li><a … Read more

Sanitize title only if only custom post type

you want to sanitize the title or the post_name (slug)? if you want to filter post_name you can check wp_unique_post_slug filter or you can use the wp_insert_post_data filter to filter all post data before insert or update in db. add_filter( “wp_unique_post_slug”, “url_sanitizer”, 10, 4 ); function url_sanitizer( $slug, $post_ID, $post_status, $post_type ) { // get … Read more