If single/category (4 posts)

  1. Piotr
    Posted 6 years ago #

    What's wrong with if(is_single(array($settings['excl_post']))==true) { ... }, because it doesn't work for 2nd, 3rd, etc. value in saved in database in 'excl_post'? They're seperated with commas like in example on codex.

    I have this problem with categories too.

  2. Peter Butler
    Posted 6 years ago #

    the array($settings['excl_post']) is just putting the contents of $settings['excl_post'] into a single element in an array. If the contents of $settings['excl_post'] are comma separated post ids, try this:

    $exclude_array = explode(',' $settings['excl_post']);
    if(is_single($exclude_array)){ ...

    You may also need to run a loop over each item in $exclude_array and get the intval() of the item to make sure what you're holding in the array is an integer, bu tI'm not sure.

  3. Piotr
    Posted 6 years ago #

    Unfortunely it doesn't work, but with a loop is great. ;) Thank you! :)

    $exclude_array = explode(",", $settings['excl_post']);
    	for ( $i = 0; $i < count($exclude_array); $i++ ) {
    	if(is_single($exclude_array[$i])==true) {...} }

    But I have one more question. Is it possible to use any conditional tag to check if element is in specific class or id (like div id="sidebar")?

  4. Peter Butler
    Posted 6 years ago #

    Glad to hear you got it working.

    If I understand your second question properly, no, I dont believe there's a way to check that. If you explain what you're trying to do though, maybe we could come up with a different method.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.