Changing an item in drop down after 5 latest posts per taxonomy

Have a closer look to the blow code- $query_args = array( ‘posts_per_page’ => ‘5’, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ); $listedPosts = new WP_Query($query_args); // the loop if ( $listedPosts->have_posts() ) { while ( $listedPosts->have_posts() ) { $listedPosts->the_post(); if ( (int) $listedPosts->current_post == 5 ) { // You need to use ‘==’ or ‘===’ … Read more

How to redirect CPT permalinks from ID to default pretty permalinks?

If I understood you correctly, you will first need to redirect your user to http://domain.com/cpt1/%postname%/ and afterward, you’ll need to rewrite the URL in order to get the correct post and avoid 404 errors. So here you go: add_action( ‘template_redirect’, ‘redirect_postid_to_postname’ ); function redirect_postid_to_postname() { $uri = $_SERVER[‘REQUEST_URI’]; // Checks if the URI matches what … Read more

Taxonomy and Custom Post type with Collpase

You can do something like this <h3> Portfólio </h3> <?php $catprod = get_terms( array( ‘taxonomy’ => ‘categoria-produto’, ‘order’ => ‘DESC’, ‘parent’ =>0, ‘hide_empty’ => false, )); // Todas as categorias ?> <div class=”panel-group”> <div class=”panel-heading”> <?php foreach( $catprod as $cat ): ?> <h3 class=”panel-title”> <a data-toggle=”collapse” href=”#<?php echo $cat->slug ?>” class=”accordion-toggle” data-parent=”#accordion”> <?php echo $cat->name … Read more

How can I save a Custom Post Title and Slug with a Custom Field?

I found some code that allows both Post Title and Slug to be generated from custom field data: function recipe_update_title( $value, $post_id, $field ) { $new_title = get_field( ‘recipe_name’, $post_id) . ‘ ‘ . $value; $new_slug = sanitize_title( $new_title ); // update post $recipe_postdata = array( ‘ID’ => $post_id, ‘post_title’ => $new_title, ‘post_name’ => $new_slug, … Read more

Keep br tags from stripping

Since any attribute added to <br> tag, including class names and data-attrs keeps them from stripping, quick and incomplete way could be: function filter_function_name( $content, $post_id ) { $content = str_replace(‘<br>’, ‘<br data-x>’, $content); $content = str_replace(‘<br >’, ‘<br data-x>’, $content); $content = str_replace(‘<br />’, ‘<br data-x>’, $content); $content = str_replace(‘<br/>’, ‘<br data-x>’, $content); return … Read more