Get_Template_Part And Two Global WP_Query On Frontpage

You shouldn’t have to globalize the main $wp_query, only secondary queries. Take the following example, if I have a very simple frontpage.php template it would look like: <?php get_header(); ?> <?php get_template_part( ‘templates/template’, ‘main-query’ ); ?> <?php get_footer(); ?> I can then create a template found in /theme-name/templates/template-main-query.php which has a normal Loop: <?php if( … Read more

Echo a shortcode div after every 3 posts

First, let’s clean up this tag SPAM nightmare so we can read it and then simplify the code: function adinserter() { return ‘abcdefg’; } if (have_posts()) { $count = 0; while (have_posts()) { the_post(); $count++; get_template_part( ‘content’, get_post_format() ); if ($count == 3) { if (function_exists (‘adinserter’)) { echo adinserter (1); } $count = 0; … Read more

Check for the main query from the template

Use in_the_loop(), it returns true if we are in the main loop, false if we are not, like on a custom query loop Return: (bool) True if caller is within loop, false if loop hasn’t started or ended. The difference between is_main_query() and in_the_loop() is that is_main_query() uses WP_Query::is_main_query() which in turn uses the global … Read more

get_template_part causes 500 error

The get_template_part() function takes filepath relative to the file it is called in. Do you have a folder called ‘content’ which contains a file content-posttype.php? is the ‘content’ folder located in the same folder as this php file you are calling get_template_part() in? Also, you can modify your while loop as follows: while ( $postsQuery->have_posts() … Read more

Tag page only display 10 posts

The problem is query_posts(). It is stomping on the default query, and killing your pagination. Don’t use query_posts(). Filter $wp_query at pre_get_posts instead: function wpse123674_pre_get_posts( $query ) { // Only modify the main query on the tag archive index if ( $query->is_main_query && $query->is_tag() ) { $query->set( ‘post_type’, array(‘post, cool_tools, tribe_events’) ); } } add_action( … Read more

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