If you’ve made it here, odds are you’ve already been through the depths of the internet, full of “simple” tutorials talking about how easy it is to pass a variable in your PHP code to Javascript in WordPress. Maybe they even have simple, foolproof examples. The only thing is, they don’t work. WHY don’t they work? Who cares! They are … Read More
Wordpress - Category Archive
Single Post Permalink Not Working and 404 for Logged-out Users – WordPress
Sometimes you may find that the permalink of a single page you have in WordPress is not working. When you are in the edit screen, it shows up fine. But when you click to view it, the permalink is something like yoursite.com/?p=14 or something along those lines. Additionally, when you try to view the page when logged out, you get … Read More
Use FTP to Create New Admin User in WordPress
I came across a really neat trick today for those times when you’ve been locked out of your own WordPress site or a client wants you to make changes to their site but never gave you login credentials. All you need is FTP access and you can create a new administrator user. Original credit for this goes to George Stephanis of … Read More
Limit Word Count in WordPress Excerpt
I came across a great way to limit the number of words displayed in the excerpt for a WordPress post, brought to you by the good folks at Cuppa (update – link removed because the site is gone). This method will allow you to choose a specific word limit every time you use the_excerpt or get_the_excerpt in your template files, … Read More
Can’t Add Pages to Custom Menu – WordPress Solution
A common problem with beginners to WordPress after they create a new site is that they are unable to add anything to their custom menu. In some cases, there are just no options to choose from to add to the menu, in others there is just a vague heading saying, “no items” as well as numerous other problems. here are … Read More
Manual Sort Order for Authors or Users – WordPress
Sometimes it’s necessary to manually select the order in which to sort your authors on your page listing all your authors or users. It is a little tricky to do, but I’ll break it down for you in this simple tutorial. First, you are going to need to add a custom meta field for your users. There are many ways … Read More
Display Only Top-Level Parent Categories – WordPress
If you are using a loop to list all your WordPress categories or terms in a custom taxonomy and you only want to display the top-level ones, here is how you do that. The trick is in getting the “parent” parameter, which is set to “0” for all top-level terms and categories. So to start a foreach loop and display … Read More
Dropdown List of Authors with Posts in Category – WordPress
While at first it may seem impossible, creating a dropdown list of all the authors with posts in a specific category is not actually all that difficult. This will work with custom taxonomies and custom post types as well, so it should suit the needs of just about anyone. Let’s get right to it! The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<form> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="">Select by Author</option> <?php //Code to get a list of all authors with posts in this category, and then create a dropdown list of their names with links to their page $category = get_queried_object(); $taxonomy_name = 'custom_taxonomy_name_here'; //Change to reflect the name of your custom taxonomy $current_category = $category->slug; echo '<h1>' . $current_category . 'testing</h1>'; $author_array = array(); $args = array( 'posts_per_page' => -1, 'post_type' => 'custom_post_type_here', //Change to your custom post type 'tax_query' => array( array( 'taxonomy' => 'custom_taxonomy_name_here', //Change to reflect the name of your custom taxonomy 'field' => 'slug', 'terms' => $current_category ), ), 'orderby' => 'author', 'order' => 'ASC' ); $cat_posts = get_posts($args); foreach ($cat_posts as $cat_post) : if (!in_array($cat_post->post_author,$author_array)) { $author_array[] = $cat_post->post_author; } endforeach; foreach ($author_array as $author) : $auth = get_userdata($author)->display_name; $nicename = get_userdata($author)->user_nicename; echo '<option value="' . get_term_link( $category->slug, $taxonomy_name ) . '/' . $nicename . '">' . $auth . '</option>'; //creates the URL to our term, filtered by author endforeach; ?> </select> </form> |
There are … Read More
Get ID of Current Category – WordPress
Getting the ID of the current category in WordPress is actually quite simple. This will work in category archive pages or anywhere a category has been queried. We are going to use get_queried_object() to accomplish this task. The following script will get all the information about our queried object and put it in an array, $category. Then we are simply … Read More
Display Future Posts Easily with query_posts – WordPress
It’s actually quite easy to include future posts in a WordPress loop using a simple query_posts with some arguments. Other information on the web makes it sound like it’s really tricky, but those people are either misinformed or lying. Let’s take a look! This tutorial assumes you are familiar with the use of query_posts to start a new query. If … Read More