New answers tagged

0

To answer about the div, you'd surround it with a div! So you'd put this: <div class="group-a"> <?php // all your existing question code here ?> </div>


2

Use the Index of the post currently being displayed to trigger when your custom content is rendered. current_post can be found on WP_Query from within the loop. <?php while( $archive_query->have_posts() ) : $archive_query->the_post(); ?> <article <?php post_class(); ?>> The Content </article> <?...


0

In general, I agree with Howdy_McGee that one should avoid overwriting the main query unless absolutely necessary - more often than not, modifying the main query with something like a 'pre_get_posts' hook is a better solution to such scenarios. Manually overwriting the global $wp_query can cause all sorts of unintended behaviors if you are not exceedingly ...


0

is_wp_error() functions return the post_ID on success. The value 0 or WP_Error on failure. $post = array( 'post_author' => 1, 'post_title' => 'my title, 'post_content' => 'my content', 'post_category' => array(3), 'post_type' => 'post', ); $ins_post = wp_insert_post($post); if(is_wp_error($ins_post)){ echo 'error'; }else{ echo '...


0

What you are doing is exactly to a T what query_posts does, and it really is a bad idea. To prove my point, here is the sorce code for query_posts() function query_posts($query) { $GLOBALS['wp_query'] = new WP_Query(); return $GLOBALS['wp_query']->query($query); } Remember, $GLOBALS['wp_query'] === $wp_query. Now, look at your code, and you'll ...


1

I feel like you should be using get_template_part() for markup. Let's say you have a Custom Template and the Blog which uses the same get_template_part(). You would call the template_part in the loop instead of calling The Loop in the part. For example: Your Custom Template $custom_query = new WP_Query( $args ); if ( $custom_query->have_posts() ) { ...


0

This is probably not the most optimal solution, but you could store static metadata as an array in the theme options. The options table is loaded in memory by default, giving you fast access.


1

You are going in wrong direction there is no way to get user role while admin change from back end. You can retrieve the role object for the current user by calling get_role(), but that's an object rather than a string with the role name. function get_user_role($uid) { global $wpdb; $role = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} ...


0

You will have to use 2 queries, where in the first loop you should use: $args = array( "post_type" => "post", "post_status" => "publish", "orderby" => "date", "order" => "DESC", "posts_per_page" => 20, 'post__in' => cat, ); (The Query) And in the second: $args = array( "post_type" => "post", "post_status" => "...


0

To search for posts based on date, you can set up a quick instance of WP_Query. The best place to look is the official documentation, and in particular the section on the date parameters. A basic search for posts in a particular month will look a little like this: <?php $the_query = new WP_Query( array( 'm' => '201607', // will return posts in ...


0

Add the below code in your active theme's functions.php file. function wpse_delete_query_transient( $post ) { // Deletes the transient when a new post is published delete_transient( 'd_results' ); } add_action( 'new_to_publish', 'wpse_delete_query_transient' ); This will delete the transient every time when a new post is published. If you want to ...


0

I'm not sure at first glance why this is only working on your home page and not your archive pages, but there are a few things wrong with the way this function is written. So, I've rewritten it for you below - using this instead might solve the problem if it was introducing an esoteric bug before. A couple of things to note: relation should not be used ...


0

Try to change 'orderby' => 'meta_value','meta_key' => 'event-date-start'


0

Check here Note: The category parameter needs to be the ID of the category, and not the category name.


1

As Tim Malone said, WP_Query isn't going to return multiple copies of the same post in its result set. I think you have a design problem and I would suggest you use parent/child posts rather than post meta to accomplish what you want. The following is one approach to doing this. First, register both post types: // The parent event type // There will be one ...


0

Change $myposts = get_posts( 'numberposts=6&offset=$debut') to $myposts = get_posts( 'numberposts=6&category_name=home-slider&offset=$debut') OR $myposts = get_posts( 'numberposts=6&category=1&offset=$debut') replace 1 with your category ID Hope this helps


0

What about using this? $args = array( 'post_type' => 'post', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( 'relation' => 'OR', array( 'key' => $end_time_1, 'value' => date('Y-m-d H:i'), 'compare' => '>=' ), array( 'key' => $...


1

REWORKED ANSWER TO ANSWER THE QUESTION In order to exclude all pages with a certain template, all you need to do is to run a meta_query to exclude all pages with the custom field _wp_page_template set to bedankt. Remember, WordPress saves the template assigned to a page as a hidden custom field called _wp_page_template With this in mind, we can do the ...


-1

// This won't show date in all cases the_date( 'F d, Y' ); // This will show date in all cases the_time( 'F d, Y' );



Top 50 recent answers are included