custom post type single page template not working

Please see the Template Hierarchy. There is no template-portfolio.php template. It needs to be archive-portfolio.php. Also, you should not be using a custom query*. Use the main query in your post type archive templates. WordPress already queries the correct posts for you. So remove: $portfolio = new WP_Query(‘post_type’=> ‘portfolio’); And replace: while ($portfolio-> have_posts() ) … Read more

WooCommerce customise checkout billing form [closed]

woocommerce_form_field in the foreach loop https://github.com/woocommerce/woocommerce/blob/master/templates/checkout/form-billing.php#L39 refers to https://github.com/woocommerce/woocommerce/blob/master/includes/wc-template-functions.php#L2607 So you can adapt the following code to your needs function change_woocommerce_field_markup( $field, $key, $args, $value ) { // Remove the .form-row class from the current field wrapper $field = str_replace(‘form-row’, ”, $field); // Wrap the field (and its wrapper) in a new custom div, adding … Read more

Custom template not working for existing pages [closed]

as a solution, you can fully automate the selection of a template for a group of pages using slug names: add_filter(‘request’, function( $vars ) { $slug = explode(“https://wordpress.stackexchange.com/”, explode(‘?’, $_SERVER[‘REQUEST_URI’])[0]); array_pop ($slug); $temp_base = “…first_part_template_name…”; $temp_slug = array_pop ($slug); if (file_exists(get_template_directory().”https://wordpress.stackexchange.com/”.$template.’-‘.$temp_cat.’.php’)) { get_template_part( $temp_base, $temp_slug ); } }

add custom css on all page exept of one

add this to end of functions.php function mmk_enqueue_script(){ if( !is_page(123) ){ wp_enqueue_style(‘responsive-css’, get_stylesheet_directory_uri() . ‘/custom.css’, false); } } add_action( ‘wp_enqueue_scripts’, ‘mmk_enqueue_script’, 999); create a custom.css inside your theme directory. this CSS file will be applied to all pages except the one you specified. update “123” inside if condition with page id where you don’t want … Read more

Getting Custom Field value in WP_Query

You need to define the $post global variable if you want to access its ID property: function excateg($categ) { global $post; $recent = new WP_Query(“cat=$categ&showposts=1”); while($recent->have_posts()){ $recent->the_post(); $imageurl = get_post_meta($post->ID, ‘post-img’, true); } } Use it after the_post() because that function will set up that variable. Alternatively you can use the $recent->post property instead of … Read more