【问题标题】:WooCommerce Memberships: How to adjust query to account for delayed content/content drip?WooCommerce 会员资格:如何调整查询以解决延迟的内容/内容滴漏?
【发布时间】:2020-07-21 09:05:20
【问题描述】:

我正在尝试构建一个查询,以显示成员有权访问的最新帖子,但我找不到要添加的参数,以便从该列表中删除他们将来可以访问的帖子。

有人知道怎么做吗?

如果没有,wc_memberships_is_post_content_restricted( ) 是否可以适应自定义循环?

编辑 我尝试添加建议的代码,但不是获取用户可以访问的最新帖子,而是输出网站上最旧的页面。我是否将其添加到错误的位置?

`<?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(); } ?>`

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce woocommerce-memberships


    【解决方案1】:

    要删除受限制的帖子标题,请选择“设置”->“内容限制模式”上的“完全隐藏”。

    如果您选择“隐藏内容”,帖子标题将继续显示在帖子导航和列表中。

    一旦我这样做了,两个循环(我的和 mujuonly 的)都工作了。

    【讨论】:

      【解决方案2】:
      foreach ( $posts as $post ) {
          if( wc_memberships_is_post_content_restricted($post->ID)){
              // do the coding here for the restricted contents
          }else{
              // do the coding here for the non-restricted contents
          }
      }
      

      试试这个代码

      【讨论】:

      • 谢谢!这帮助我发现我的代码出现了一些错误。
      猜你喜欢
      • 2022-08-22
      • 2016-10-08
      • 2015-06-27
      • 2020-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 2020-12-08
      相关资源
      最近更新 更多