Skip to main content
deleted 41 characters in body
Source Link

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

SOLUTION

Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:

function standard_term_filter( $query ) {
    if ( ! $query->is_admin )
    || ! isset( $_GET['sms_premium_posts!'] return) $query;
)
    $term = isset( $_GET['sms_premium_posts!'] ) ? $_GET['sms_premium_posts!'] :return null;$query;

    if ( $term && 'premium' == $term$_GET['sms_premium_posts!'] ) {
        $taxquery = array(
            array(
                'taxonomy' => 'sms_premium_posts',
                'field'    => 'slug',
                'terms'    => 'premium',
                'operator' => 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
    }
    return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );

Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().

Also note the ! at the end of my query string term: sms_premium_posts!

I made my Standard term links look like this:

http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

SOLUTION

Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:

function standard_term_filter( $query ) {
    if ( ! $query->is_admin )
        return $query;

    $term = isset( $_GET['sms_premium_posts!'] ) ? $_GET['sms_premium_posts!'] : null;
    if ( $term && 'premium' == $term ) {
        $taxquery = array(
            array(
                'taxonomy' => 'sms_premium_posts',
                'field'    => 'slug',
                'terms'    => 'premium',
                'operator' => 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
    }
    return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );

Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().

Also note the ! at the end of my query string term: sms_premium_posts!

I made my Standard term links look like this:

http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

SOLUTION

Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:

function standard_term_filter( $query ) {
    if ( ! $query->is_admin || ! isset( $_GET['sms_premium_posts!'] ) )
        return $query;

    if ( 'premium' == $_GET['sms_premium_posts!'] ) {
        $taxquery = array(
            array(
                'taxonomy' => 'sms_premium_posts',
                'field'    => 'slug',
                'terms'    => 'premium',
                'operator' => 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
    }
    return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );

Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().

Also note the ! at the end of my query string term: sms_premium_posts!

I made my Standard term links look like this:

http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.

added 1267 characters in body
Source Link

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

SOLUTION

Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:

function standard_term_filter( $query ) {
    if ( ! $query->is_admin )
        return $query;

    $term = isset( $_GET['sms_premium_posts!'] ) ? $_GET['sms_premium_posts!'] : null;
    if ( $term && 'premium' == $term ) {
        $taxquery = array(
            array(
                'taxonomy' => 'sms_premium_posts',
                'field'    => 'slug',
                'terms'    => 'premium',
                'operator' => 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
    }
    return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );

Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().

Also note the ! at the end of my query string term: sms_premium_posts!

I made my Standard term links look like this:

http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

SOLUTION

Based on the answer from @s_ha_dum below, here is what I did to fake a negative query string:

function standard_term_filter( $query ) {
    if ( ! $query->is_admin )
        return $query;

    $term = isset( $_GET['sms_premium_posts!'] ) ? $_GET['sms_premium_posts!'] : null;
    if ( $term && 'premium' == $term ) {
        $taxquery = array(
            array(
                'taxonomy' => 'sms_premium_posts',
                'field'    => 'slug',
                'terms'    => 'premium',
                'operator' => 'NOT IN'
            )
        );
        $query->set( 'tax_query', $taxquery );
    }
    return $query;
}
add_action( 'pre_get_posts', array( $this, 'standard_term_filter' ) );

Note that I added this function as a method of my plugin class, which is why I used an array for the callback in add_action().

Also note the ! at the end of my query string term: sms_premium_posts!

I made my Standard term links look like this:

http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

Since sms_premium_posts! is different than sms_premium_posts (the slug of my custom taxonomy), it works.

Question formatting
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

I wrote a plugin (http://wordpress.org/plugins/premium-posts/Premium Posts) that registers a custom taxonomy called 'sms_premium_posts'sms_premium_posts and adds a column to the post list table in WP-Adminthe WordPress administration area.

In that custom column, if a post has been marked 'Premium'Premium, the term 'Premium'Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://mydomain.com/wp-admin/edit.php?sms_premium_posts=premiumhttp://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as 'Premium'Premium, I would like the term 'Standard'Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that? Something like:

http://mydomain.com/wp-admin/edit.php?sms_premium_posts!=premiumExample query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term 'Standard' to all other posts?""Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

I wrote a plugin (http://wordpress.org/plugins/premium-posts/) that registers a custom taxonomy called 'sms_premium_posts' and adds a column to the post table in WP-Admin.

In that custom column, if a post has been marked 'Premium', the term 'Premium' links to a filtered list of only premium posts. This link is generated using the query string:

http://mydomain.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as 'Premium', I would like the term 'Standard' to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that? Something like:

http://mydomain.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term 'Standard' to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

I wrote a plugin Premium Posts that registers a custom taxonomy called sms_premium_posts and adds a column to the post list table in the WordPress administration area.

In that custom column, if a post has been marked Premium, the term Premium links to a filtered list of only premium posts. This link is generated using the query string:

http://www.example.com/wp-admin/edit.php?sms_premium_posts=premium

If a post is not marked as Premium, I would like the term Standard to filter the list so the table only shows posts that are NOT marked as premium (i.e. posts with no taxonomy terms).

Is there a query string for that?

Example query string:
http://www.example.com/wp-admin/edit.php?sms_premium_posts!=premium

You may ask, "Why not add the term Standard to all other posts?" My reason for not doing that is, it would require tagging all existing posts with a custom taxonomy term when the plugin is activated...which seems pretty inefficient.

Thanks in advance!

Source Link
Loading