When using Post Type Switcher the tags get left behind (this will move them ALL which isn’t always what you want). UPDATE wp_term_taxonomy SET taxonomy=’portfolio_tag’ WHERE taxonomy=’post_tag’ UPDATE wp_term_taxonomy SET taxonomy=’portfolio’ WHERE taxonomy=’category’
Grid of Taxonomies
Some options to add a grid of taxonomy pages. The first doesn’t include pageing the second requires adding a second post type to hold the pages. // no pageing with this one function jma_series_grid ($atts){ ob_start(); extract( shortcode_atts( array( ), $atts ) ); $series_array = get_terms( ‘series’ ); foreach ($series_array as $series) {//get values from […]
Placeholder Text with jQuery
This is for the constant contact widget: jQuery(document).ready(function($){ /* Put any theme-specific JS here… */ $ccwidget = $( ‘.widget_sf_widget_constantcontact’ ); $ccwidget.find(‘label’ ).css(‘display’, ‘none’); $ccwidget.find(‘input[name=”fnm”]’ ).attr(‘placeholder’, ‘First Name’); $ccwidget.find(‘input[name=”lnm”]’ ).attr(‘placeholder’, ‘Last Name’); $ccwidget.find(‘input[name=”eml”]’ ).attr(‘placeholder’, ‘Email’); });
Query Revision (pre_get_posts)
function jma_add_custom_taxonomy_query( $query ) { if( $query->is_admin || !$query->is_main_query() || true == $query->query_vars[‘suppress_filters’] ) return; //order cats by title (use ‘name’ for slug) if( $query->is_category(array(148,160,161)) ) { $query->set(‘orderby’, ‘title’); $query->set(‘order’, ‘ASC’); } } add_action( ‘pre_get_posts’, ‘jma_add_custom_taxonomy_query’ );
No Frills Pdf Button
function pdf_button_filter( $content ) { $pre_content = $post_content = ‘<a class=”pdf-button btn” href=”javascript:pdf_url=location.href;location.href=\’http://pdfmyurl.com?s=l&url=\’+escape(pdf_url)”>A pdf button!</a>’; $content = $pre_content . $content . $post_content; return $content; } function add_pdf_button_content(){//whatever template condition you want here //if(is_single())//for just posts //if(is_page())//for just pages if(is_singular( ‘park’ ))// park is the custom post type add_filter(‘the_content’, ‘pdf_button_filter’, 1); } add_action(‘template_redirect’, ‘add_pdf_button_content’);
Display List of Related Pages from Hierarchy in Sidebar
Linked pages related to the current page. If is root page shows itself as title with all children below. Else shows immediate parent as title with all pages at its level below (depth can be changed, with -1 showing all without hierarchy). function jma_sidebar_addon() { global $post; if($post->post_parent) { $children = wp_list_pages(‘title_li=&child_of=’.$post->post_parent.’&echo=0&depth=1′); }else{ $children = […]
Get Image ID from Source
Finds the image id given the source. Or returns false. function get_attachment_id_from_src( $attachment_url = ” ) { global $wpdb; $attachment_id = false; // If there is no url, return. if ( ” == $attachment_url ) return $attachment_id; $query = “SELECT ID FROM {$wpdb->posts} WHERE guid=’$attachment_url'”; if($wpdb->get_var($query)){ $attachment_id = $wpdb->get_var($query); }else{ // If this is the […]
Multi-site Menu (experimental)
Starting in 4.7 using REST API – This is JumpStart specific. On “host” site: function get_menu() { # Change ‘menu’ to your own navigation slug. return wp_nav_menu(themeblvd_get_wp_nav_menu_args(‘primary’)); } //https://hosturl.com/wp-json/myroutes/menu add_action(‘rest_api_init’, function () { register_rest_route(‘myroutes’, ‘/menu’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_menu’, )); }); On “receiving” site: function jma_child_header_menu_addon() { $response = wp_remote_get(‘https://hosturl.com/wp-json/myroutes/menu’); /*echo ‘<pre>’; […]
Display Posts by Category [shortcode]
Suppose we want to display a list of post links in the sidebar that are in “child” categories of the “News” category (ie “Boating News” followed by its posts, “Fishing News” followed by its posts, in this case from the last 90 days because of the filter). We could include this code in functions.php: add_filter(‘widget_text’, […]