Skip to content
Advertisement

WooCommerce Memberships: How to adjust query to account for delayed content/content drip?

I’m trying to build a query that shows the latest post a member has access to, but I cannot find what parameters to add so that posts that they have access to in the future are removed from this list.

Does anyone know how to do this?

If not, can wc_memberships_is_post_content_restricted( ) be adapted into a custom loop?

EDIT I tried adding the code suggested, but instead of getting the latest post a user has access to, it outputs the oldest page on the site. Am I adding it to the wrong place?

`<?php
    // Query Test
    $args = array(
      'post_type' => 'premium',
      'posts_per_page' => 1,
      'tax_query' => array(
            array(
                'taxonomy' => 'notebook',
                'field' => 'term_id',
                'terms' => 425,
            ),
        ),
      );
    $query4 = new WP_Query( $args );
    if ( $query4->have_posts() ) {
    // The Loop
    while ( $query4->have_posts() ) {
    $query4->the_post();

    foreach ( $posts as $post ) {
    if( !wc_memberships_is_post_content_restricted($post->ID)){

      echo the_title();
    }
    }
    } wp_reset_postdata(); } ?>`

Advertisement

Answer

To remove restricted post titles select “Hide Completely” on Settings -> “Content Restriction Mode.”

If you select “Hide Content” post titles will continue to show up on post navigation and lists.

Once I did this both loops (mine and mujuonly’s) worked.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement