Need help writing loop to display posts by categories in separate divs
Need help writing loop to display posts by categories in separate divs
Need help writing loop to display posts by categories in separate divs
I think you should make a recursion function that will call itself if there’s no posts found passing new date to query for.. function getDatePosts( $date, $query_args ) { $query_args[‘date_query’] = array( ‘year’ => date( ‘Y’, $date ), ‘mounth’ => date( ‘m’, $date ), ‘day’ => date( ‘d’, $date ) ); $query = new WP_Query( … Read more
You could use an Action Hook ‘save_post‘ to implement the requirement and this way categories will stay synced with your custom table and default tables. Example : function post_updated_sync_category( $post_id ) { //Here you get postid of the post being updated //You can put your code to update in custom table here } add_action( ‘save_post’, … Read more
so it was $wp_query->set(‘nopaging’, true); Which was set in a pre_get_posts function. I never thought of searching for this. I’ve added if(!is_admin()){ // code } So it doesn’t run in the admin.
One potential issue I see with that is if the content contains Shortcodes. You can strip Shortcodes before passing it to wp_trim_words if you want them removed, or alternately, if you want to maintain them you can apply the Shortcodes beforehand. You may also want to check that $news_item[“post_excerpt”] is not empty, in case a … Read more
If you don’t care about the URL of this page, you can do it without Ajax, using $_GET parameters. Take a look: // If we have $_GET parameter in URL, we save it in $page variable. Otherwise $page will be empty. ( isset( $_GET[‘page’] ) ) ? $page = ( int ) $_GET[‘page’] : $page=””; … Read more
You can use a hook developed for such kind of purposes: post_updated Use this hook whenever you need to compare values before and after the post update. Lets get some codding: function mail_on_update($post_ID, $post_after, $post_before){ if($post_after->post_content != $post_before->post_content){ // wp_mail() , mail() here } } add_action( ‘post_updated’, ‘mail_on_update’, 10, 3 ); // 10 – priority, … Read more
i think your question has been answered in here $args = array(‘posts_per_page’ => -1, ‘orderby’ => ‘date’ ); $myQuery = new WP_Query($args); $date=””; if ( $myQuery->have_posts() ) : while ( $myQuery->have_posts() ) : $myQuery->the_post(); if ( $date != get_the_date() ) { echo $date; echo ‘<hr />’; $date = get_the_date(); } the_title(); // or whatever you … Read more
You can use the wordpress plugin ‘Ajax Load More‘ which facilitates you with the features of loading more posts on the same page.
Normally you would write a function that gets called by the save_post hook, and use wp_update_post to update the post. The problem is, when you call wp_update_post it calls save_post, which will cause an infinite loop. To get around that, we will unhook our function before calling wp_update_post, then re-hook it afterward. I have not … Read more