-1

Keep getting syntax error, not sure why. This is the code I'm using

function my_epl_listing_default_sort($query) {
    // Do nothing if in dashboard or not an archive page
    if ( is_admin() || ! $query->is_main_query() )
        return;

    // Do nothing if Easy Property Listings is not active
    if ( ! function_exists( 'epl_all_post_types' ) )
        return;

    // Do nothing if doing search
    if ( epl_is_search() )
        return;

    /// Sort EPL listings by price on archive page
    if ( is_post_type_archive( epl_all_post_types() == 'true' ) ) {
        $query->set( 'meta_key', 'title' );
        $query->set( 'order',    'ASC' );
        $query->set( 'orderby',  'meta_value'  );
        return;
    }
}
add_action( 'pre_get_posts', 'my_epl_listing_default_sort' );

closed as off-topic by Mark Kaplun, TheDeadMedic, Jacob Peattie, Jack Johansson Aug 18 '18 at 12:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – TheDeadMedic, Jacob Peattie, Jack Johansson
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    The error message would have told you the error and the line it was occurring on. At least include the full error. – Jacob Peattie Aug 15 '18 at 3:48
  • If you get a syntax error it means that you wrote bad PHP. It will be hard to spot such things on the site. If you got other error.... well the question is pointless without showing it, you should edit the question and add it – Mark Kaplun Aug 15 '18 at 6:48
1

It’s hard to be sure without he error, but this part of code looks pretty weird:

if ( is_post_type_archive( epl_all_post_types() == 'true' ) ) {

is_post_type_archive gets one param and it should be post type or array of post types.

But in your code you pass a logical statement in there (so true or false).

So I can’t be 100% sure that this is the cause of error you’re getting, but most certainly this is the reason why this code won’t work correctly ;)

PS. Also... The epl_all_post_types function returns an array, so it doesn’t make much sense to compare it with true.

Not the answer you're looking for? Browse other questions tagged or ask your own question.