Best way to Order Post in Home without a plugin
Best way to Order Post in Home without a plugin
Best way to Order Post in Home without a plugin
date() PHP functions returns the value of time() PHP functions in the specified format. time() use server local time. If you want to get date/time based of WordPress configuration, you could use current_time(), a WordPress function, instead of native PHP functions. // ‘timestamp’ = Unix Timestamp or ‘U’ PHP time format $current_time = current_time( ‘timestamp’ … Read more
WP Meta Query at depth 2
You can use WP_Query for this: $query = new WP_Query( array( ‘post_type’ => ‘my_cpt’ ) ); This will query only posts of the type my_cpt. To search only for posts with a certain first or last name, you have to extend the query. For this you need to add the field meta_query: $query = new … Read more
For custom field queries you can’t use an array for multiple keys, unfortunately. What you want is something like this: $args = array( ‘post_type’ => array(‘gym_location’, ‘gym_term’), ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘term_active’, ‘value’ => ‘1’, ‘compare’ => ‘==’ ), array( ‘key’ => ‘location_active’, ‘value’ => ‘1’, ‘compare’ … Read more
First: don’t use query_posts. It will confuse the main WordPress loop. You will need two queries. First use the query you have already constructed to get the priority posts: $query1 = new WP_Query( $args ); // here use the $args you already have Now count how many posts are returned to set the maximum return … Read more
Nested arrays can be used to create complex Meta Query’s. An example of how this would apply to your situation. $meta_query_args = array( ‘relation’ => ‘AND’, array( // Conditions ), array( ‘relation’ => ‘OR’, array( // Conditions ), array( // Conditions ) ) ); For more information check: https://codex.wordpress.org/Class_Reference/WP_Meta_Query
Both examples of your code throw errors on the while line: <?php while ( $users_query->have_posts(): $users_query->the_post() ) ?> The while will work if you move the parenthesis from the end to before the colon, and replace the parenthesis with a semicolon. <?php while ( $users_query->have_posts() ) : $users_query->the_post() ; ?> (The Errors turn up fast … Read more
If you only want to get the CPT that have the meta_key, then u can remove value and compare and it should work.
I have solved the problem myself: What I did is: First created single-football_league.php template where i placed following codes: <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content-parts/content’, ‘league’ ); ?> <?php endwhile; ?> Second: In content-league.php, I placed following codes, and it works: $terms = wp_get_post_terms( $post->ID, array(‘competition’, ‘session’) ); $term_slugs = … Read more