Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter xscv2314

    (@xscv2314)

    Well I finally found an answer

    function instant_articles_query_modified($query) {
        if($query->is_main_query() && isset(INSTANT_ARTICLES_SLUG) && $query->is_feed(INSTANT_ARTICLES_SLUG)) {
            $query->set('meta_query', array(
                array(
                      'key' => 'your_required_meta'
                )
            ));
    }
    add_action('pre_get_posts', 'instant_articles_query_modified', 10, 2);

    Wow, great.
    Did you put this code in your functions.php?
    And what is “Key”? How can I choose/mark the articles? With custom fields?
    Thanks

    Thread Starter xscv2314

    (@xscv2314)

    key is the name of the field (eg actor_name, image_field etc). Then you can add a ‘value’ and ‘compare’ entry to the array so that you can check the content of the custom field you want to use. See here.

    Also you can check the answer link above for a better explanation.

    Kay, I understand. But when I add the code above I get an Server Error 500.
    Is there a missing } or )? Can’d find the bug.

    Yes, it’s missing a brace for the if statement.

    function instant_articles_query_modified($query) {
        if($query->is_main_query() && isset(INSTANT_ARTICLES_SLUG) && $query->is_feed(INSTANT_ARTICLES_SLUG)) {
            $query->set('meta_query', array(
                array(
                      'key' => 'your_required_meta'
                )
            ));
        }
    }
    add_action('pre_get_posts', 'instant_articles_query_modified', 10, 2);

    Does this only work for the RSS version, or is it successfully excluding/including these items with the API connected?

    Still getting Server-Error :/

    phpcodechecker.com recommends replacing isset(INSTANT_ARTICLES_SLUG) with null!==INSTANT_ARTICLES_SLUG. I made that change on very similar code, and it worked.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Prevent article from being included in the feed’ is closed to new replies.