How to limit the number of Related Posts?

You need the argument post_per_page to limit the posts. Before your loop it should be something like this. $args = array ( ‘post_type’ => ‘custom_post’, ‘posts_per_page’ => ’10’, ); $wp_query = new WP_Query( $args ); // your loop if ( $wp_query ->have_posts() ) { while (have_posts()) : the_post(); get_template_part( ‘preview’, get_post_format() ); endwhile; } wp_reset_postdata(); … Read more

Change the file path on get_template_part via plugin

Well, I handle this issue by adding some code above get_template_part() function in theme as: //Theme /* If any filter set */ if(has_filter(‘ppr_one_search_item_view’){ $themePartSlug = apply_filters(‘ppr_one_search_item_view’); } else{ $themePartSlug = ‘templates/search/place’; } get_template_part($themePartSlug); in my plugin: /* Plugin Code */ function get_template_part_place(){ // Template file from plugin Directory load_template(PPR1_PLUGIN_PATH.’templates/search_places.php’); } add_filter( ‘ppr_one_search_item_view’, ‘get_template_part_place’); /* plugin … Read more

add a hook with get_template_part()

OK, so one simple way would be to edit your template, I assume header.php for where you want the menu to appear. Use the template include to load myfile.php get_template_part(‘template-parts/myfile’); Then inside myfile.php: <?php $search .= ‘<li class=”search”><form role=”search” method=”get” id=”searchform” action=”‘.home_url( “https://wordpress.stackexchange.com/” ).'”><input type=”text” value=”search” name=”s” id=”s” /><input type=”submit” id=”searchsubmit” value=”‘. esc_attr__(‘Search’) .'” /></form></li>’; … Read more

Using get_template_part to retrieve a template file based on current post type

There is built in support for that, kind of. While I don’t see anything wrong with your code, try naming your files on the form archive-mytype.php, content-mytype.php etc. and then call get_template_part like this: <!– This will result in including parts/content-mytype.php –> <?php get_template_part(‘parts/content’, get_post_type( $post )); ?> <p id=”t3-splash-title”><?php $post_type = get_post_type_object( get_post_type($post) ); … Read more

Problem with using get_template_part() in footer

It looks like the code in contactform.php may be causing issues. These lines, specifically: global $wp; wp_redirect(home_url($wp->request)); exit; The exit statement may be stopping execution of the rest of the script. If you want to process form data, you should be checking for it and processing it instead of just running the redirect and exit … Read more

Is there a tirck in the get_xxxx function in the general_template.php file?

The do_action: do_action( ‘get_header’, $name ); its triggering the action get_header, so all actions attached using add_action to the action ‘get_header’ will be executed, its also passing the $name as parameter to the functions by example: function my_function($name){ echo “The Action sent me the name:”.$name.”!!”; } add_action(‘get_header’, ‘my_function’); when the do_action( ‘get_header’, $name ); is … Read more

tech