This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Let's say you're parsing query args in the admin so | |
* that you can apply some custom filters for your | |
* custom post type list table. | |
*/ | |
add_filter( 'parse_query', 'filter_my_post_type' ); | |
function filter_my_post_type( $query ) { | |
/** | |
* Oh good, you've put in that is_admin() check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I'm going to add some content from one post to | |
* the content of another post. Yay for me. | |
*/ | |
add_filter( 'the_content', 'my_little_content_addition' ); | |
function my_little_content_addition( $content ) { | |
if ( is_the_right_content() ) { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Load a .mo file for the old textdomain if one exists | |
* | |
* If you have to change your textdomain to comply with upcoming | |
* plugin and theme repository standards, this function will check to | |
* see if an old translation file exists and load it if it does, so | |
* that people don't lose their translations. | |
* | |
* h/t: https://github.com/10up/grunt-wp-plugin/issues/21#issuecomment-62003284 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Don't sort your custom post type admin lists this way because it will | |
* override other sorting being executed on this list. | |
*/ | |
add_action( 'pre_get_posts', array( $this, 'admin_order_posts' ) ); | |
public function admin_order_posts( $query ) { | |
if( ( is_admin() && $query->is_admin ) && $query->get( 'post_type' ) == 'my_custom_post_type' ) { | |
$query->set( 'orderby', 'menu_order' ); | |
$query->set( 'order', 'ASC' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check before sorting your custom post type admin lists so you don't | |
* override other changes. | |
*/ | |
add_action( 'pre_get_posts', array( $this, 'admin_order_posts' ) ); | |
public function admin_order_posts( $query ) { | |
if( ( is_admin() && $query->is_admin ) && $query->get( 'post_type' ) == 'my_custom_post_type' ) { | |
// This prevents other orderby options from breaking. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Register a single setting to store all of your options in the database | |
*/ | |
register_setting( 'myslug_option_group', 'myslug', 'myslug_sanitize_options_array' ); | |
/** | |
* Define each of your settings | |
*/ | |
add_settings_field( | |
'name', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ( is_category() || is_tag() || is_tax() ) && $summary = term_description() ) : ?> | |
<div class="term-summary"> | |
<?php echo $summary; ?> | |
</div> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set up a global for storing settings in your product | |
* (if you're using classes, store it in a controller) | |
*/ | |
global $myprefix_settings; | |
/** | |
* Set up your own wrapper for accessing settings in | |
* your product | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Go ahead. Do your fancy shit | |
*/ | |
$your_query = new WP_query( 'post_type' => 'your_cool_post_type' ); | |
while( $your_query->have_posts() ) { | |
$your_query->the_post(); | |
/** | |
* Look at your cool template function. | |
* That looks just like my template function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select name="tedious"> | |
<?php foreach( $options as $value => $label ) : ?> | |
<option value="<?php echo $value; ?>" <?php if ( $value === $current_value ) { echo 'selected="selected"'; } ?>"><?php echo $label; ?></option> | |
<?php endforeach; ?> | |
</select> |
OlderNewer