Too many categories drastically slow down my website
Too many categories drastically slow down my website
Too many categories drastically slow down my website
Yes, it´s totally possible, I just did that for a similar project some weeks ago. I found this very helpful: How to pass extra variables in URL with WordPress Basically the process is the following: Register new query_vars, fill them with life, pass them to a specific template which looks for them and then do … Read more
Getting Post Tags From Certain Categories
Try this <?php global $post; ?> <article id=”post-<?php the_ID(); ?>” <?php post_class( ‘entry’ ); ?><?php echo et_fable_get_background(); ?>> <div class=”container clearfix”> <header class=”entry-title”> <?php if ( is_single() ) : ?> <h1><?php the_title(); ?></h1> <?php else : ?> <h2> <a href=”https://wordpress.stackexchange.com/questions/208008/<?php the_permalink(); ?>”><?php the_title(); ?></a> </h2> <?php endif; ?> <?php //et_fable_post_meta(); ?> </header> <?php if ( … Read more
This should work (if your post_type is not post you will need to amend the code) <?php $args = array( ‘post_type’ => ‘post’, ‘cat’ => ’31’, ‘posts_per_page’ => 5, ); $query = new WP_Query( $args );?> <?php if( $query->have_posts() ) : ?> <?php while( $query->have_posts() ) : $query->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/209558/<?php the_permalink(); ?>”><i class=”fa fa-book”></i> … Read more
If you can access the database directly, you could Check for the ID of the category you want to assign Check for the Author ID Then run the following MySql (on your own risk): INSERT INTO `#__term_relationships` ( object_id, term_taxonomy_id ) SELECT ID, 1 FROM `#__posts` WHERE `post_type` = ‘post’ // where 1 is your … Read more
Multiple Loops Outside the loop you can get available terms of the core taxonomy category with get_terms( ‘taxonomy_name’ ). The resulting array contains objects like object(stdClass)#141 (9) { [“term_id”] => string(1) “3” [“name”] => string(9) “The Name of your Category” [“slug”] => string(9) “name-of-tax-term” [“term_group”] => string(1) “0” [“term_taxonomy_id”] => string(1) “3” [“taxonomy”] => string(11) … Read more
The function get_ancestors() will give you an array containing all of the parents of your category with the nearest ancestor being first in the array. So: $cid = 5; // your category ID $c = get_ancestors($cid,’category’); var_dump($c); // debugging $p = array_shift($c); // var_dump($p); // debugging Use $p to do whatever you need to do.
I just recently did this with a custom post type and custom taxonomy with the following code. function cpt_assign_term($post_id) { $current_post = get_post( $post_id ); // Only apply to new posts. if ( $current_post->post_date == $current_post->post_modified ) { wp_set_object_terms( $post_id, ‘default-term_name-or-id’, ‘category’, true ); } } add_action( ‘save_post_{your-post-type}’, ‘cpt_assign_term’ ); https://codex.wordpress.org/Function_Reference/wp_set_object_terms
I solved my problem. All I needed was the WordPress Rewrite API. if( ! function_exists(‘theme_add_rewrite_rules’) ){ function theme_add_rewrite_rules(){ add_rewrite_rule( ‘^blog/([^/]+)/?$’, ‘index.php?name=$matches[1]’, ‘top’ ); } } add_action( ‘init’, ‘theme_add_rewrite_rules’); This solves how wordpress will parse the URL. Half of the problem is how to modify the posts so that the links will not include the /en/ … Read more