Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2.  
  3. // Ref: https://wordpress.org/support/topic/noindex-a-page-via-php/
  4.  
  5. add_filter( 'the_seo_framework_post_meta', function( $meta, $post_id ) {
  6.  
  7.     // Only adjust stocks post types.
  8.     if ( 'stocks' !== get_post_type( $post_id ) ) return $meta;
  9.  
  10.     // Don't do anything when ACF isn't active.
  11.     if ( ! function_exists( 'get_field' ) ) return $meta;
  12.  
  13.     $page_type = get_field( 'page_type', $post_id );
  14.  
  15.     if ( in_array( $page_type, [ 'financialsincq', 'financialsbsq', 'financialscfq' ], true ) ) {
  16.  
  17.         $root_id      = get_field( 'root_id', $post_id );
  18.         $api_data_raw = get_field( 'fundamentals_quarterly', $root_id );
  19.  
  20.         list( $data ) = json_decode( $api_data_raw, true );
  21.         $count        = count( $data['datatable']['data'] );
  22.  
  23.         if ( $count < 5 ) {
  24.             // -1 = force index, 0 = default, 1 = force noindex.
  25.             $meta['_genesis_noindex'] = 1;
  26.         }
  27.     } elseif ( in_array( $page_type, [ 'financials', 'financialsbsa', 'financialscfa' ], true ) ) {
  28.  
  29.         $root_id      = get_field( 'root_id', $post_id );
  30.         $api_data_raw = get_field( 'fundamentals_annual', $root_id );
  31.  
  32.         list( $data ) = json_decode($api_data_raw, true);
  33.         $count        = count( $data['datatable']['data'] );
  34.  
  35.         if ( $count < 1 ) {
  36.             // -1 = force index, 0 = default, 1 = force noindex.
  37.             $meta['_genesis_noindex'] = 1;
  38.         }
  39.     }
  40.  
  41.     return $meta;
  42. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement