Is there any method to check options table existence?

I am writing a method that is responsible for creating table, and it depends on an option.

When I run this on a fresh database, it throws error that options table does not exists. Is there any prepared method in wordpress for checking of options table existence?

I am using following code for checking a specific option and then creating required table:

if (!get_option('my_specific_key', 0)) {

   ... running sqls here

Go to Source
Author: BABAK ASHRAFI

WP_query has incorrect wp_posts.post_name = ‘asc’ when I have custom post type called ‘order’

This is my code :

print_r($args)

//Output 
array(6) { ["post_type"] => string(9) "order" 
           ["date_query"] => array(2) { 
               ["before"] => string(3) "now" 
               ["compare"] => string(1) "=" 
           } 
           ["post_status"] => string(9) "validated" 
           ["posts_per_page"] => int(-1) 
           ["orderby"] => string(5) "title"
           ["order"] => string(3) "ASC" 
         } 

And this is the request :

$wp_query = new WP_Query( $args );
var_dump( $wp_query->request );
  
//Output 
"SELECT wp_posts.* 
 FROM wp_posts 
 WHERE 1=1 
 AND ( wp_posts.post_date < '2020-08-07 16:46:27' ) 
 AND wp_posts.post_name = 'asc'
 AND wp_posts.post_type = 'order'
 AND ((wp_posts.post_status = 'validated'))
 ORDER BY wp_posts.post_title ASC "

So WP_Query in the query says wp_posts.post_name = 'asc' !!!

Why ?

Go to Source
Author: J.BizMai

Randomly sort part of already sorted query

I’m not entirely sure how to word my question, but I’ll give it a go.

Basically, what I’m wanting to do is order a group of posts by a custom field. I have a True/False custom field, created using the ACF plugin, which is displayed on a certain custom post type.

Right now, I’ve set up a query to firstly display posts with the True/False statement set to true, and then to display the posts with the statement set to false. This is working well.

What I want to do, however, is take the posts with the true statement and randomly change their order. All while keeping the current order or True first and then False in place.

Here is my current query.

                $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                
                // the query
                $wpb_all_query = new WP_Query(array('post_type'=>'businesses', 'post_status'=>'publish', 'category_name'=>basename(get_permalink()), 'meta_key'=>'featured', 'orderby'=>'meta_value','order'=>'DESC', 'posts_per_page'=>20, 'paged' => $paged)); ?>

                    <?php if ( $wpb_all_query->have_posts() ) : ?>
                
                
                    <!-- the loop -->
                    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>

Go to Source
Author: Timothy Davis

WP_Query show the posts in sequence of tags entered in Query

Basicly I want to show the post in sequence of what the tags entered are.

For instance this is my Query:

$args = array(
    'post_type'              => array( 'providers' ),
    'post_status'            => array( 'publish' ),
    'tag' => array( 'speed', 'price', 'contract', 'network' ),
);                                             
$the_query = new WP_Query( $args );

I would like to show the post with the tag ‘speed’ first and ‘network’ last. I could not find a matching ‘orderby’ in the wordpress codex. I’m wondering if someone here knows how to do this.

Thank you!

Go to Source
Author: Kevin M.

ACF Date Based wp_query

I’ve been trying to order these exhibitions based on the end_date custom field created with Advanced Custom Fields. I’m not able to properly get this working. I need the most recent dates first. I need to also only get posts with the exhibition_status of ‘past’. For the life of me I can’t get this working and the below code is just the latest non working interation.

$args = array (
'post_type'         => 'exhibitions',
'meta_query'        => array(
    'relation'      => 'OR',
        'query_one'     => array(
            'key'       => 'exhibition_status',
            'value'     => 'past', // Optional
        ),
        'query_two'     => array(
            'key'       => 'end_date',
            'compare'   => '>=',
        ), 
),
'orderby'                => 'end_date',
'order'                  => 'ASC',
'post_status' => 'publish',
'posts_per_page' => 10,
'paged' => get_query_var( 'paged' ),

);

Go to Source
Author: smack-a-bro