how to loop through blog posts in php

$args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ); $the_query = new WP_Query( $args ); If you set the posts_per_page to -1 it will return all posts. Then you can loop through and do what you want with the single post. while ( $the_query->have_posts() ) { echo get_the_author_meta( );//I have NOT used this so … Read more

Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT

OK, so finally after searching for days i was able to solve my problem!! Just had to remove these two lines of code: $terms = wp_get_post_terms( $post->ID, ‘service_cat’ ); foreach($terms as $term) { With this line instead: $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); And that solved my issue!! Thanks also … Read more

Is there any way of not using my_init_method in the following code (that creates a custom post type)?

What is the error message being generated? Also, to avoid conflicts, all custom Theme functions, classes, options, constants, etc. should be prefixed uniquely, e.g. using theme-slug. It is highly likely that a generic function name like my_init_method is used by another Plugin or Theme. Try renaming it to mytheme-slug_init_method. EDIT: To implement, rename your function … Read more

Header location [closed]

HTML code: <h4 id=”yourId”><span><strong>100%</strong></span></h4> CSS: code #yourId { position: top: 10px; right: 10px; position: absolute; } If you need it to stay always there even if you’re scrolling then use this one #yourId { position: top: 10px; right: 10px; position: fixed; }

metabox displaying on incorrect page

Dropping the code quickly into my test set up, I think you are asking why your page metabox is showing your desired post meta inputs. There’s no problem with your add_meta_box() functions. The problem is with your variable $custom_meta_fields. By the time WordPress gets to the end of your file $custom_meta_fields is defined by the … Read more

How to implement a custom sliding banner? [closed]

There are a lot of slider pluglins in wordpress repository such http://wordpress.org/plugins/slide-show-pro/, just follow the install steps. then use the shortcodes like [slideshowpro cats=2,3] or the code to integrate into php php echo do_shortcode(‘[slideshowpro cats=2,3]’); insert the code in header.php to show the slider on every single page or post

WordPress: code structure

I find that very easily my views become cluttered with logic, e.g. null checks, email validation, and retrieving values from the post object. How would you separate this out in WordPress? Is there any sort of MVC framework? There is no clear separation enforced by WordPress and there is extremely wide range of styles and … Read more