get all page templates

Only the page post type can have a template assigned (of the default post types), it’s the custom template you set in the Page Attributes meta box. If you have a page.php template file, your index.php will only be used to display post post types, so those posts will never have a _wp_page_template meta key. … Read more

Using Query In Post Type Archives

Change it from: ‘category_name’ => celebrity, ‘orderby’ => 1, into ‘category_name’ => ‘celebrity’, ‘orderby’ => ‘date’, // or something else Otherwise celebrity will be treated as a constant name, not a string. Also, you can’t order by 1, you have to use one of the ordering parameters.

Custom loop page with post navigation

I ended up creating two loops and utilizing anchors. I’m not sure if it’s the most efficient way of doing things, however, it works. add_action( ‘genesis_post_content’, ‘child_do_content’ ); // Adds your custom page code/content function child_do_content() {?> <ul class=”multicol”> <?php $custom_query = new WP_Query(array(‘orderby’ => ‘title’, ‘order’ => ‘ASC’,’cat=5′)); while($custom_query->have_posts()) : $custom_query->the_post();?> <li><a href=”#<?php the_title(); … Read more

Custom Meta Box If Else Statement

You can try this: <?php // get image source: $metaboxtext3 = esc_attr( get_post_meta( get_the_ID(), ‘my_meta_box_text3’, true ) ); // get link: $metaboxtext4 = esc_attr( get_post_meta( get_the_ID(), ‘my_meta_box_text4’, true ) ); // check if the image source exists: if(strlen($metaboxtext3)>0){ ?> <a href=”https://wordpress.stackexchange.com/questions/84788/<?php echo $metaboxtext4; ?>”><img src=”<?php echo $metaboxtext3; ?>” alt=”” onerror=”this.style.display=’none'”/></a> <?php } ?>

single.php fires more than once after clicking on any post to view with different post id each time

I am answering this because nobody yet answered this and I think this could help others who are experiencing this kind of issue. As mentioned by s_ha_dum that the issue is related to FireFox’s Prefetching mechanism. In order to resolve this I inserted the below line to function.php: remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’);

Loop through multiple custom taxonomy terms and display posts for a custom post type

If you look at your var_dump, near the end, you will see the actual query being used. SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (93) ) AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’) AND (wp_posts.post_status=”publish” OR wp_posts.post_author = 1 AND wp_posts.post_status=”private”) GROUP BY wp_posts.ID ORDER BY … Read more

Trying to display ads on only a third of posts in a loop. Keep getting Error 500?

echo “<img src=\”” . bloginfo(‘template_url’); . “/img/sample-ad-side.png\” alt=\”Sample Advertisement\”>”; You added a semicolon, what comes after that semicolon is a new statement. . “img/ etc is not valid PHP, so it errors out. Also bloginfo does not return its value, it prints it, so you need to change that to get_bloginfo. I would suggest you … Read more