How can I define the output of shortcode attribute value?

According to Codex: function shortcode_function_name( $atts ) { $atts = shortcode_atts( array( ‘attr1’ => ”, ), $atts, ‘your-shortcode-name’ ); return ‘<div id=”‘.$atts[‘attr1′].'”>Your Predefined Content</div>’; } add_shortcode( ‘your-shortcode-name’, ‘shortcode_function_name’ ); Adding [your-shortcode-name attr1=”Value1″] to the content of any post/page will give the following output <div id=”Value1″>Your Predefined Content</div>. Adding [your-shortcode-name attr1=”Value1″] to the content of any … Read more

WordPress custom search – pagination

Working code: $display_count = 2; global $wp_query, $paged; $pages = $wp_query->max_num_pages; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $offset = $page – 1; $showposts = 10; $args = array( ‘showposts’ => 20, ‘post_type’ => ‘any’, ‘post__in’ => $WPIDs, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘cf_dimensjon’, ‘order’ => ‘ASC’, ‘number’ => $display_count, ‘paged’ => $paged ); $wp_query … Read more

How to loop through 1 CPT with 2 Taxonomies

You probably want to use wp_get_post_terms(). If a product is always associated to only one category – which has no child if hierarchical – (what I understand from your example), adding below snippet within your while loop should do it (not tested). <? $cat = wp_get_post_terms( get_the_ID(), ‘department’ ); echo ‘<span>(‘ . $cat->name . ‘)</span>’; … Read more

Custom permalink based on custom post type fields

Look at the filter for rewrite_rules_array and add a re-write rule to re-write /products/category-name/sub-category-name/product-name to index.php?pagename=product-name. You might need to grab the category-name and sub-category-name too if your product-names are not unique. Then add a query var for product-name using the query_vars filter. Once you’ve done that in your new post type template you can … Read more