• Resolved philipt18

    (@philipt18)


    I have a loop where I’m searching for posts that are from a specific category and match a tag (or tags). The tags are grabbed from a custom field. If the custom field is empty it should return no results, but instead is returning all results in that category. How can I get it to properly return no results? Thanks.

    https://wordpress.org/plugins/custom-content-shortcode/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    If the custom field is empty, you’re not querying for any tags:

    [loop type="post" category="something" tag=""]

    ..so the loop returns all posts in that category.

    For the result you want, you’ll have to check the custom field, and if it’s empty, then not run the loop:

    [if field="field_name"]
      [loop ..][/loop]
    [else]
      Field is empty.
    [/if]
    Thread Starter philipt18

    (@philipt18)

    And if I’m passing the field? Would this be correct?

    [pass field="taglist"]
    	[if field="{FIELD}"]
    		[loop type="post" category="catname" tag="{FIELD}"]
    		[field title-link]
    		[/loop]
    	[else]
    		Nothing found.
    	[/if]
    [/pass]
    Thread Starter philipt18

    (@philipt18)

    I’m guessing not because now everything says ‘Nothing found’.

    Plugin Author Eliot Akira

    (@miyarakira)

    I think this should work:

    [if field="taglist"]
    Thread Starter philipt18

    (@philipt18)

    I moved the if to the outside like:

    [if field="taglist"]
    	[pass field="taglist"]
    		[loop type="post" category="catname" tag="{FIELD}"]
    		[field title-link]
    		[/loop]
    	[/pass]
    [else]
    	Nothing found.
    [/if]

    and it seems to be working. Thanks.

    Plugin Author Eliot Akira

    (@miyarakira)

    Great, I’m glad that worked.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Empty search returning ALL results instead of NONE’ is closed to new replies.