0
votes

My site uses JetPack to include infinite scroll on archive pages and to create a portfolio CPT.

This is causing problems on the portfolio archive page, so I want to turn off infinite scroll on this page

Here is what I am trying (including an alert to show which page type is loaded):

// Add theme support for Infinite Scroll.
if ( 'post_type' != 'portfolio' ) :
  echo '<script language="javascript">';
  echo 'alert("Not a Portfolio page")';
  echo '</script>';

    add_theme_support( 'infinite-scroll', array(
        'container' => 'main',
        'footer'    => 'false', // edited was page
      'render'    => 'thisSite_infinite_scroll_render',
    ) );
else :
  echo '<script language="javascript">';
  echo 'alert("is a Portfolio page")';
  echo '</script>';

  add_theme_support( 'infinite-scroll', array(
    'container' => 'main',
    'footer'    => 'false', // edited was page
    'render'    => 'false',
  ) );
endif;

Trouble is that 'post_type' != 'portfolio' is not working, nor does 'post_type' != 'jetpack-portfolio'

How do I test for this condition?

1
Are you aware of the fact that if ( 'post_type' != 'portfolio' ) is a condition were a fixed string literal is compared with another different string literal, meaning this will always evalutate to true? This makes the if-branch kind of useless.Striezel
OK that is what is wrong with it. How would you do it correctly?justsomeone

1 Answers

0
votes

you need to use if( get_post_type() == 'post_type_slug' )

So in your case

if( get_post_type() == 'portfolio' )
  { 
      // do your stuff 
  } 

It retrieves the post type of the current post or of a given post. see the details at Wordpress https://developer.wordpress.org/reference/functions/get_post_type/