5 added 674 characters in body
source | link

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;}

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');

This won't work...

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

...because Wordpress uses the orderby-argument here to include orderby only.

(I guess WP would create a query something like this:

order by wp_posts WHERE wp_posts.post_type = 'brand-listing'
where wp_posts_type = 'post' //default created by wordpress

and therefore sql is incorrect (two where clauses) )

If you still want to use post_clauses you should be able to use this:

$clauses['orderby'] = "{$wpdb->posts}.post_title";
$clauses['where'] = "{$wpdb->posts}.post_type = 'brand'";

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;}

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;}

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');

This won't work...

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

...because Wordpress uses the orderby-argument here to include orderby only.

(I guess WP would create a query something like this:

order by wp_posts WHERE wp_posts.post_type = 'brand-listing'
where wp_posts_type = 'post' //default created by wordpress

and therefore sql is incorrect (two where clauses) )

If you still want to use post_clauses you should be able to use this:

$clauses['orderby'] = "{$wpdb->posts}.post_title";
$clauses['where'] = "{$wpdb->posts}.post_type = 'brand'";
4 added 267 characters in body
source | link

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;}

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;}

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');
3 added 267 characters in body
source | link

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
 
    if(is_admin()){            
        $post_types( =! get_post_types$query->is_main_query();
 || ! is_admin() {return;

    $post_type = $query->get('post_type');

        if ($post_type == 'brand') {            
            $query->set( 'orderby', array('title' => 'ASC') );
        }
 
    }
}
add_action('pre_get_posts', 'custom_post_order');

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

/* Sort posts in wplist admin */
function custom_post_order($query){
 
    if(is_admin()){            
        $post_types = get_post_types();
        $post_type = $query->get('post_type');

        if ($post_type == 'brand') {            
            $query->set( 'orderby', array('title' => 'ASC') );
        }
 
    }
}
add_action('pre_get_posts', 'custom_post_order');

It seems like your mixing slug and post-type. Slug is used to identify a page/post when some entering it into the browser (very related to a permalink). A post type is used to identify what kind of post that is stored in the wordpress database.

post_clauses is used if you want to change several things in a query at once. I would recommend using pre_get_posts instead (if you don't want to do more complex queries than ordering)

Based on what you've wrote:

$clauses['orderby'] = " {$wpdb->posts}.post_title WHERE {$wpdb->posts}.post_type = 'brand-listing'";

it seems like you only want orderby posts that custom post type brand (not brand-listing that seems to be the slug?)

/* Sort posts in wplist admin */
function custom_post_order($query){
    if ( ! $query->is_main_query() || ! is_admin() {return;

    $post_type = $query->get('post_type');

    if ($post_type == 'brand') {            
        $query->set( 'orderby', array('title' => 'ASC') );
    }

}
add_action('pre_get_posts', 'custom_post_order');
2 added 318 characters in body
source | link
1
source | link