Default permalink structure causing Notice: Undefined property: WP_Query::$post

Finally I found what causing this problem, turns out it have to do with my pre_get_post hook. Because I using is_page to check the specific page, which is not appropriate. Here is what I did function check_page($wp_query){ if($wp_query->is_page(array(‘1′,’2′,’3’)) ){ //do something here } return $wp_query; } add_action( ‘pre_get_posts’, ‘check_page’ ); So my solution to this … Read more

Don’t change Custom Post Type slug to unique value

you might consider the ‘wp_unique_post_slug’ filter: add_filter( ‘wp_unique_post_slug’,’my_disable_unique_slug’,11,6); function disable_unique_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ){ global $post; if($post->post_type==’cpt’){ // EDIT post type $slug=$original_slug; } return $slug; } This is untested, but you get the idea 😉 ps: you might have to change other things to make this work, since the unique-ness is so … Read more

get_posts post title permalink not working for last item in array

You should use a foreach loop instead, as the count index isn’t the best way to walk over an array. <?php $speakerarray = get_post_meta($post->ID, ‘cpt_food’, true); foreach($speakerarray as $foodname) : $posts = get_posts(array(‘name’ => $foodname, ‘post_type’ => ‘food’)); $post = $posts[0]; echo ‘<a href=”‘ . get_permalink( $post->ID ) . ‘>’ . $foodname . ‘</a><br>’; endforeach; … Read more

Use the category name instead of category slug in permalinks

I did not test this, but this should do what you want. Put the following in your functions.php: add_filter(‘rewrite_rules_array’, ‘new_category_name_rewrite_rule’); function new_category_name_rewrite_rule($rules) { $new_rules = array(); $categories = get_categories(); foreach ($categories as $category) { $cat_name = preg_replace(‘#\s+#’, ‘-‘, $category->name); $new_rules[“https://wordpress.stackexchange.com/”.$category->slug.”https://wordpress.stackexchange.com/”] = “https://wordpress.stackexchange.com/”.urlencode($cat_name).”https://wordpress.stackexchange.com/”; } return $new_rules + $rules; }

How can I redirect this contact form to a specific permalink

If your form has been incorporated into WordPress as a page template, which I encourage, then get_permalink(8); // or 12 should do it. If not, then http://example.com/?p=8 and http://example.com/?p=12 should always work. http://example.com/?page_id=8 and http://example.com/?page_id=12 uses the proper parameter for pages but ?p= works fine when I test it.

implement separate templates for 1 post type

You may use template redirect action to check if there is parameter set for description and based on that you can show desired template. <?php add_action(‘template_redirect’, ‘course_template_redirect’, 1); function course_template_redirect() { global $wp_query; if($wp_query->post_type==’courses’ and $_REQUEST[‘showdesc’]==’1′) { //include your template from your theme folder. for e.g include(‘mytheme/coursetemplate.php’); } } ?>

Using one slug/post-name for multiple pages

This is not natively possible, since in your example permalink structure posts are detected by slug alone, and not combination with category. Essentially category info gets simply discarded. If your requirements involve only one (few) of possible endings for URL you might achieve this relatively easy using endpoints, see add_rewrite_endpoint(). However in generic scenario slug … Read more

Permalink Settings

mod_rewriteis probably not activated on your localhost that why permalink can’t work. Just uncomment this line in apache : #LoadModule rewrite_module modules/mod_rewrite.so