Query Custom Posts – Add To Selection

Use wp_reset_postdata(); to restore the global $post variable of the main query loop after a secondary query loop using new WP_Query. It restores the $post variable to the current post in the main query. call wp_reset_postdata(); after endwhile; <?php while($org->have_posts()) : $org->the_post(); ?> <option value=”<?php echo $post->post_name; ?>”><?php the_title(); ?></option> <?php endwhile; // reset main … Read more

WordPress Permalink Redirect 301

Don’t use php header function it will cause problems within wordpress. WordPress has its own function to make redirects Function Reference: wp_redirect($url, $status_code); Try this: <?php $permalink = get_permalink( $id ); wp_redirect($permalink, 301); exit; ?> Updated: I’ve worked out some code for you Place this below code to your functions.php file: function redirector($post_id) { if … Read more

Custom post type 404 error on “default” or “numeric” permalinks

The URL you are trying to access– mysite.com/reading-list/— is constructed by the WordPress rewrite rules. The path /reading-list/ doesn’t actually exist. If you are using the default ?p=123 links, those rewrite rules are not used. The default links are just GET strings. In other words, since there is nothing at mysite.com/reading-list/ without the rewrite rules … Read more

How to get links to user and tag by its name?

Use the get_user_by and get_term_by functions: // user $user = get_user_by( ‘login’, ‘someuser’ ); if( $user ){ echo get_author_posts_url( $user->ID ); } // tag $term = get_term_by( ‘name’, ‘Sometag’, ‘post_tag’ ); if( $term ){ echo get_term_link( $term ); }

Passing variables through permalink structure in custom post types

The one issue I see immediately with your rewrite rule is this part: index.php?pagename=charities You don’t have a page named “charities”, you have a custom post type, so that should be: index.php?charities=$matches[1] assuming your custom post type query var is charities. HOWEVER, that said, I would not add rewrite rules for this, WordPress will take … Read more