CPT while loop not working

Your post type is all wrong. Custom post type names cannot contain spaces or camelcase, also names should not contain special characters. Custom post type names, and for that matter, custom taxonomy names should be all lowercase letters, and names must only be separated by underscores (_) Have a look at the $post_type parameter in … Read more

Integrating WordPress with Your Website

If I understand your needs correctly, you would like to have your /blog page and post items aggregated and driven by WordPress without exposing the user to anything WordPress. To solve the problem with “wordpress” being in the url, you should actually be putting the entire contents of the WordPress install into the website.tld/blog directory. … Read more

how can i order the category by date

When the instance of WP_Query is not a variable on the PHP file you are working on it tends to be the “main” query and to edit this instance of the WP_Query you will need to Hook to the pre_get_posts action and change what you need there. Here is an Exemple: <?php add_action( ‘pre_get_posts’, ‘q166401_pre_get_posts’, … Read more

Frontpage pagination by week

Use the page number to calculate a new date to get the week to fetch: $page = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $date_to_fetch = time() – ( 604800 * ( $page – 1 ) ) ); $query_string = array( ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘year’ => date( … Read more

query_posts clarification needed

Can someone please explain how “$posts” is used within the loop? It isn’t. It returns the array of queried posts , but it is insignificant and not used at all: if you remove it than the code works the same: global $query_string; query_posts($query_string.’&cat=-9′); if (have_posts()) : while (have_posts()) : the_post(); … endwhile; endif; This is … Read more

add_action in the loop hooks

Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action). To stop this, the action should be removed. See remove_action: function do_entry() { if ( get_the_title() ) { add_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } else { remove_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } add_action(‘loop_entry_entry’, ‘function_that_adds_content_structure’); } In your case, I … Read more