Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Ref: https://wordpress.org/support/topic/noindex-a-page-via-php/
- add_filter( 'the_seo_framework_post_meta', function( $meta, $post_id ) {
- // Only adjust stocks post types.
- if ( 'stocks' !== get_post_type( $post_id ) ) return $meta;
- // Don't do anything when ACF isn't active.
- if ( ! function_exists( 'get_field' ) ) return $meta;
- $page_type = get_field( 'page_type', $post_id );
- if ( in_array( $page_type, [ 'financialsincq', 'financialsbsq', 'financialscfq' ], true ) ) {
- $root_id = get_field( 'root_id', $post_id );
- $api_data_raw = get_field( 'fundamentals_quarterly', $root_id );
- list( $data ) = json_decode( $api_data_raw, true );
- $count = count( $data['datatable']['data'] );
- if ( $count < 5 ) {
- // -1 = force index, 0 = default, 1 = force noindex.
- $meta['_genesis_noindex'] = 1;
- }
- } elseif ( in_array( $page_type, [ 'financials', 'financialsbsa', 'financialscfa' ], true ) ) {
- $root_id = get_field( 'root_id', $post_id );
- $api_data_raw = get_field( 'fundamentals_annual', $root_id );
- list( $data ) = json_decode($api_data_raw, true);
- $count = count( $data['datatable']['data'] );
- if ( $count < 1 ) {
- // -1 = force index, 0 = default, 1 = force noindex.
- $meta['_genesis_noindex'] = 1;
- }
- }
- return $meta;
- }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement