I use following function to get my custom posts ordering by title

$posts = get_posts(
    array(
        "orderby"=> "title",
        "order" => "ASC",
        "post_type" => "my-custom-post-type",
        "posts_per_page" => -1,
        "fields" => "ids",
        "meta_query" => array(
            array(
                "key" => "ams_park_id",
                "value" => get_the_ID(),
            )
        )
    )
);

And it orders by title, the problem is that i have one posts that have is titled: “It’s a small world”, and this is being ordered at the beginning of the list.

Example of the current returning list:

0 - "It's a small world"
1 - Albatross
2 - Alligator
3 - Baboon
4 - Camel
5 - Fox
6 - Hino
7 - Iguana
8 - Jackal
9...

How can i make to make the selector ignore the quote and send it to the “i” part of the order? Example:

0 - Albatross
1 - Alligator
2 - Baboon
3 - Camel
4 - Fox
5 - Hino
6 - Iguana
7 - "It's a small world"
8 - Jackal
9...

3 Answers
3

Try this…

$posts = get_posts(
    array(
        "orderby"=> "slug",
        "order" => "ASC",
        "post_type" => "my-custom-post-type",
        "posts_per_page" => -1,
        "fields" => "ids",
        "meta_query" => array(
            array(
                "key" => "ams_park_id",
                "value" => get_the_ID(),
            )
        )
    )
);

Noticed I changed "orderby"=> "title", to "orderby"=> "slug". Typically the slug will be close to the title but all of the special characters will be removed.

Leave a Reply

Your email address will not be published. Required fields are marked *