WordPress autocomplete.php adding support for custom post_type?

Hi,

So got everything working fine, however, I can not figure out how to target my custom post type in autocomplete.php.

Basically, I would like to add and remove some fields specifically for a custom post type only.

Here is my code so far:

  <script type="text/html" id="tmpl-autocomplete-post-suggestion">
<# if ( data.post_type === reviews ) { #>
<a class="suggestion-link" href="test" title="{{ data.post_title }}">
  <# if ( data.images.thumbnail ) { #>
    <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}">
    <# } #>
      <div class="suggestion-post-attributes">
        <span class="suggestion-post-title">{{{ data._highlightResult.post_title.value }}}</span>
        <# if ( data._snippetResult['content'] ) { #>
          <span class="suggestion-post-content">{{{ data._snippetResult['content'].value }}}</span>
          <# } #>
      </div>
</a>
<# } else if { #>
  <a class="suggestion-link" href="{{ data.permalink }}" title="{{ data.post_title }}">
  <# if ( data.images.thumbnail ) { #>
    <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}">
    <# } #>
      <div class="suggestion-post-attributes">
        <span class="suggestion-post-title">{{{ data }}} {{{ data._highlightResult.post_title.value }}}</span>
        <# if ( data._snippetResult['content'] ) { #>
          <span class="suggestion-post-content">{{{ data._snippetResult['content'].value }}}</span>
          <# } #>
      </div>
</a>
<# } #>

As you can see I am trying to run a IF statement for my CPT reviews. This isn’t working though. Is there a way to do this correctly?

Thanks

Figured this one out. Accidentally used:

} if else {

Instead of

} else {

1 Like