Preventing index.php?category_name=something from redirecting

This should work: add_action( ‘init’, ‘wpa12742_init’ ); function wpa12742_init(){ add_rewrite_rule( ‘category/(.+?)/(\d{4})/?$’, ‘index.php?category_name=$matches[1]&year=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘category/(.+?)/(\d{4})/page/(\d+)/?$’, ‘index.php?category_name=$matches[1]&year=$matches[2]&paged=$matches[3]’, ‘top’ ); } EDIT On second thought, that’s not enough, since you’ll get caught by redirect_canonical(). Add this too: add_filter( ‘term_link’, ‘wpa12743_term_link’, 10, 3 ); function wpa12743_term_link( $link, $term, $taxonomy ){ if(‘category’ != $taxonomy && !preg_match( ‘@^\d{4}$@’, get_query_var(‘year’) … Read more

Displaying a WooCommerce product via PHP

Use do_shortcode(). For example, in a template, if you were wanting to display products specifically by ID: <?php echo do_shortcode(‘[products ids=”1, 2, 3, 4, 5″]’); ?> WooCommerce comes with several shortcodes which can be used to insert content inside posts and pages: http://docs.woothemes.com/document/woocommerce-shortcodes/ You can add shortcodes to a post or page easily via the … Read more

Loading custom page template via plugin

To add custom template in page attributes template section you have to first add your template to dropdown and load it in template_include hook when current page has selected it as current template. /** * Add “Custom” template to page attirbute template section. */ function wpse_288589_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) { // Add custom … Read more

Different widgets on different page templates?

You will need to create more sidebars in your functions.php file and then edit the page templates to call the sidebar you want. Adding sidebars Go in to your functions.php file. You should see some sidebars already being registered. The code will look something like this: //Adds default sidebar if ( function_exists(‘register_sidebar’) ) register_sidebar(); To … Read more

Add custom fields when specific templates are selected

Can you do that? Absolutely! You simply need to query the _wp_page_template meta key value of the $post object, and act accordingly. Perhaps something like so: // Globalize $post global $post; // Get the page template post meta $page_template = get_post_meta( $post->ID, ‘_wp_page_template’, true ); // If the current page uses our specific // template, … Read more

How do you check if a WordPress template file exist?

So I would add to the Answer the following: function foo_function() { $located = locate_template( ‘home.php’ ); if ( !empty( $located ) ) { // ‘home.php’ found in Theme, do something } } add_action(‘init’, ‘foo_function’); // remember to change both of the parameters above, first one for where you want the // action to happen … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)