Brian Fegter
  • Member for 10 years, 7 months
  • Last seen this week
3 answers
10 votes
35k views
Exclude Current Post from Recent Posts Loop
Accepted answer
34 votes

This the post__not_in arg should work dandy for you: $args = array( 'numberposts' => 5, 'offset' => 0, 'category' => 7, 'post__not_in' => array( $post->ID ) ); $...

View answer
3 answers
25 votes
79k views
How to add code to Header.php in a child theme?
Accepted answer
30 votes

I would hook into the wp_head action. I would place this in a plugin so as to abstract it from your presentation layer. This allows for scalability and changing of themes. This also prevents any ...

View answer
2 answers
17 votes
6k views
Generating Thumbnails for video
Accepted answer
21 votes

You can use the oEmbed functionality baked into WordPress. Typically any video host on this list will return a thumbnail to you using oembed. Here is a list of default providers that WordPress uses ...

View answer
5 answers
10 votes
32k views
How to disable posts and use pages only
Accepted answer
17 votes

You can simply hide the posts menu by adding the following to your functions.php file: function remove_posts_menu() { remove_menu_page('edit.php'); } add_action('admin_menu', 'remove_posts_menu');...

View answer
2 answers
11 votes
11k views
How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
Accepted answer
17 votes

You can simply hide the options using CSS. This will add a display:none style to the misc and minor publishing actions on the post.php and post-new.php pages. It checks for a specific post type as ...

View answer
1 answers
13 votes
19k views
Create API for single sign-on with 3rd party site
Accepted answer
16 votes

Cross-site Scripting Issues You cannot transfer WP auth cookies between domains. You also don't want to store plaintext passwords for logging into another WP installation programmatically. So, you'll ...

View answer
4 answers
9 votes
28k views
Using custom/dynamic "slug" for a page
Accepted answer
15 votes

Create a Page Template Add a new page and give it the slug stores Add A Public Query Variable add_filter('query_vars', 'add_state_var', 0, 1); function add_state_var($vars){ $vars[] = 'state'; ...

View answer
1 answers
10 votes
17k views
Custom Post Types and template_redirect
Accepted answer
13 votes

You should be using the template_include filter for this: add_filter('template_include', 'wpse_44239_template_include', 1, 1); function wpse_44239_template_include($template){ global $wp_query; ...

View answer
3 answers
42 votes
976 views
Does WordPress send data about your blog to WordPress.org or Automattic?
13 votes

WordPress sends version data back to .org when using the .org API (installing/searching/updating) to my knowledge. That data is then collated into chart graphics. You can see the data here. I assume ...

View answer
2 answers
3 votes
5k views
Delete posts from a post type automatically via Cron
Accepted answer
13 votes

Although I do not understand the motivation for truncating posts, I think this exercise is valuable for you to understand how to use cron + WordPress. Create a function to truncate posts This can be ...

View answer
3 answers
7 votes
5k views
Create a page without adding a page in the Database
Accepted answer
13 votes

To wit, this technically isn't a 'page', however it's a way to surface content using mod_rewrite. The goal here is to add a URI segment of foobar that will trigger a custom query, then include the ...

View answer
1 answers
10 votes
580 views
Developing, Testing and Releasing
Accepted answer
12 votes

There is a bit of personal philosophy that goes into a deployment workflow. It's not an easy question to answer outright without knowing your experience with servers and version control, your ...

View answer
6 answers
7 votes
16k views
Nice way to print_r arrays
Accepted answer
12 votes

I created a Kint plugin that works really well. I also integrates with the Debug Bar plugin. You can download it at: http://wordpress.org/extend/plugins/kint-debugger/ There are a few functions to ...

View answer
2 answers
7 votes
14k views
How set featured posts using checkbox in post edit screen?
10 votes

You can do this by following these steps: Add a custom meta box to your posts Create a function to save the meta data using the save_post action Add the 'meta_key' query argument to whatever query ...

View answer
3 answers
5 votes
12k views
Echo all meta keys of a custom-post TYPE
Accepted answer
10 votes

You can use a simple query to get a distinct list of user-entered meta_keys for a specific post type, then cache the results using the Transients API. The meta keys from this query will be those that ...

View answer
1 answers
3 votes
4k views
Redirect blog page to latest post?
Accepted answer
10 votes

You can use the get_posts() function: <?php /* Template Name: Redirect */ $args = array( 'posts_per_page' => '1', 'post_type' => 'post' ); $post = get_posts($args); if($post){ $...

View answer
4 answers
11 votes
8k views
Redirect Main Site to Subsite in Multisite Wordpress
Accepted answer
10 votes

You can use the parse_request action to accomplish this. Simply enable this plugin on your primary blog. Place the following code in a .php file and upload it to your plugins directory. /* Plugin ...

View answer
2 answers
2 votes
7k views
Sending out scheduled emails
Accepted answer
10 votes

You cannot rely on wp-cron for consistent results so you have to look to the server level. Most enterprise-level Wordpress installations need some sort of consistent automation. This is how I automate ...

View answer
2 answers
2 votes
4k views
Disable revisions for a specific post type only?
9 votes

If you don't have control over the post type registration, you an use the remove_post_type_support() function: add_action('admin_init', 'disablew_revisions'); function disable_revisions(){ ...

View answer
2 answers
8 votes
22k views
why doesn't the_content() work in this {single-custom_post_type.php} page?
9 votes

There's a good chance your HTML is not included in the loop. Make sure your code looks like this: if(have_posts()): while(have_posts()): the_post(); ?> <div class="publication-info"> ...

View answer
3 answers
5 votes
8k views
Get entire page content (generated HTML in browser)
8 votes

You can use output buffering to accomplish this. Add a high priority hook directly before the template is rendered: add_action('template_redirect', 'foo_buffer_go', 0); function foo_buffer_go(){ ...

View answer
1 answers
1 votes
27k views
Displaying a featured image (only img url) as the img src?
Accepted answer
7 votes

Here are the functions you need to be aware of: http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id http://codex.wordpress.org/Function_Reference/wp_get_attachment_url http://codex....

View answer
6 answers
11 votes
54k views
Can't enqueue scripts in the footer?
7 votes

You are passing a bool value to the dependency param. Try this: wp_enqueue_script( 'replace', get_template_directory_uri().'/js/jquery.ba-replacetext.min.js', array('jquery'), ...

View answer
3 answers
7 votes
8k views
Custom columns on edit-tags.php main page
Accepted answer
7 votes

You can do this by hooking into the 'taxonomy'_edit_form and edited_'taxonomy' actions. add_action('taxonomy_edit_form', 'foo_render_extra_fields'); function foo_render_extra_fields(){ $term_id = ...

View answer
2 answers
4 votes
972 views
WP_Post_List_Table::get_views - Have post counts account for filters?
Accepted answer
6 votes

You might want to remove those counts and replace them with your own. function insert_post_counts($views){ //Run your query to count posts //use wp_cache_set and wp_cache_get to optimize ...

View answer
1 answers
4 votes
2k views
First three images in post excerpt
Accepted answer
6 votes

You can do this pretty easily using the do_shortcode function. Check if an instance of [gallery] exists in your post content. Here's a simple function to drop in functions.php that checks the ...

View answer
1 answers
4 votes
1k views
W3 Total Cache, RackSpace Cloud Files, and Forcing Downloads
Accepted answer
6 votes

This can be broken down to a simple task by adding a custom filter. You will need to add the following to the _send_request method within the CF_Http class in cloudfiles_http.php line 1283. $headers ...

View answer
1 answers
1 votes
1k views
Loop through all media library images and return those where caption contains the text carousel
Accepted answer
6 votes

You could do this pretty easily with a simple query: global $wpdb; $results = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%...

View answer
2 answers
2 votes
6k views
Moving wp-content outside of web root?
6 votes

I would highly recommend that you NOT move wp-content outside of the docroot. WordPress utilizes wp-content for more than uploads. This would have a huge impact on the accessibility of themes and ...

View answer
2 answers
1 votes
2k views
Can I attach an image to a different post?
Accepted answer
6 votes

This works for me: http://wordpress.org/support/topic/detach-amp-re-attach-media-attachment-images-from-posts#post-1609173 I've saved this as a snippet in my IDE for use in projects. Very handy!

View answer
1
2 3 4 5
9