Custom permalink not working and showing 404 page not error

I had the same technical need as you, and I have did this(code below) to get it work : function my_custom_rewrite_tag() { add_rewrite_tag(‘%xxx%’, ‘([^&]+)’); //change the regex to your needs add_rewrite_tag(‘%yyy%’, ‘([^&]+)’); //change the regex to your needs } add_action(‘init’, ‘my_custom_rewrite_tag’, 10, 0); function my_custom_rewrite_rule() { add_rewrite_rule(‘^tour/([^/]*)/([^/]*)/?’,’index.php?pagename=tour&xxx=$matches[1]&yyy=$matches[2]’,’top’); } add_action(‘init’, ‘my_custom_rewrite_rule’, 10, 0); Finally, do not … Read more

Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’

You shouldn’t do it in a shortcode, you should enqueue this particular JavaScript file only for the page you want. Place something like this in your functions.php: function my_custom_scripts() { if( is_singular(‘job’) ){ wp_enqueue_script(‘jobpostingschema’, get_stylesheet_directory_uri() . ‘/js/jobpostingschema.js’, array(), ”, false); } } add_action(‘wp_enqueue_scripts’, ‘my_custom_scripts’);

Custom post type slug 404

You are missing with_front in rewrite which is true by default. Change it to something like this ‘rewrite’ => array( ‘slug’ => ‘apps’, ‘with_front’ => false, ) See the docs 💡 Bonus tip: You should avoid using flush_rewrite_rules() there, it’s quite heavy and affects performance. You should ONLY use it when modifying rewrite_rules outside of … Read more

display posts of custom post type with custom taxonomy

I would use “get_the_terms” to get the terms related to the post instead of “get_terms”, here is a quick suggestion (not tested) $args=array( ‘post_type’=>’tour_package’, ‘post__not_in’ => array(get_the_ID()), ‘posts_per_page’=> 5, ‘caller_get_posts’=>1,//handle sticky post but not in first ); $categories = get_the_terms( get_the_ID(),’tour_category’ ); if ($categories) { $category_ids = array(); foreach($categories as $individual_category){ $category_ids[] = $individual_category->term_id; } … Read more

How do I know if a rewritten rule was applied?

I’m not very sure of what you’re trying to achieve, but I hope this answer can help. 🙂 With the way your custom post type is being registered, WordPress will create custom rewrite rules such as below for the CPT’s single post pages: RegEx: ballinfo/([^/]+)(?:/([0-9]+))?/?$ Query: index.php?balls=$matches[1]&page=$matches[2] So for the following question: how do I … Read more

Update all published posts at once

I would have preferred to put this as a comment, but space does not allow for it so sorry about that. It might help you rather than being an answer. I am using ‘product’, but it could just as easy be ‘post’. function update_all() { $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ); … Read more

Custom Category Walker with Image, Fallback to Most Recent Post in Category Image

The solution to the problem is that the tax_query needs to be an array of arrays. Thank you Sally CJ for the comment above, which also reminded me to $query->request. Here’s the total Walker for anyone for whom it’s useful: class List_Category_Walker extends Walker_Category { function start_el( &$output, $category, $depth = 0, $args = array(), … Read more