WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
Warning Error 161 (6 posts)

  1. JustBlog
    Member
    Posted 1 year ago #

    I'm getting the following error when use this in widget logic:
    global $post; return (in_array(38,get_post_ancestors($post)));

    The error: Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/myhosting/public_html/wp-content/plugins/widget-logic/widget_logic.php(161) : eval()'d code on line 1

    Can someone please let me know what's wrong?

    Thanks!

    http://wordpress.org/extend/plugins/widget-logic/

  2. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    get_post_ancestors changed subtly in WP3.5

    see the suggestions here

    http://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array

    Note to self to add this to the FAQ

  3. JustBlog
    Member
    Posted 1 year ago #

    Hi Alan,

    Thanks for reply but I don't quite get what the code means.

    I put in the following code and it appears in every pages.

    global $post; if ( ($post) && !in_array(112,get_post_ancestors($post))) return true;

    I only want it to appear in post 112 and its ancestors.

    What should i do?

    Thanks!

  4. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    There are 2 problems I can see. One is the ! which is saying if $post is NOT in the list of ancestors. The other is that you've left it open what's returned when your 'if' is not true - perhaps the default is true, hence this statement could always return true.

    Try

    global $post; return ( ($post) && in_array(112,get_post_ancestors($post)));

  5. JustBlog
    Member
    Posted 1 year ago #

    Hi Alan,

    It still doesn't show anything using the coding you provided.

  6. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    well i wasn't convinced that the default return was true - i was grasping a bit there.

    sorry, I don't know what more the problem can be - you could try troubleshooting using a PHP widget that uses print_r to print out the array returned by get_post_ancestors which would help work out where things are going awry

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.