Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction Not Recognized in Private PHP Array
    primarykey
    data
    text
    <p>I have the following code based on <a href="https://gist.github.com/1229641" rel="nofollow">this great template</a> for making custom WordPress widgets: </p> <pre><code>&lt;?php class DRCC_Feat extends WP_Widget { function dr_post_select_list() { $drcc_posts_args = array( 'post_type' =&gt; array( 'post', 'page', 'tribe_events' ), 'numberposts' =&gt; -1, 'orderby' =&gt; 'title', 'order' =&gt; 'ASC' ); $drcc_posts = get_posts( $drcc_posts_args ); $dr_posts_array = array(); foreach( $drcc_posts as $post ) { $dr_posts_array[$post-&gt;ID] = $post-&gt;post_title; } return $dr_posts_array; } protected $widget = array( 'description' =&gt; 'Custom widget for my client.', 'do_wrapper' =&gt; true, 'view' =&gt; false, 'fields' =&gt; array( array( 'name' =&gt; 'Post to Feature', 'desc' =&gt; 'Enter the IDs of any posts, pages, etc. If more than one, separate with commas.', 'id' =&gt; 'dr_feat_ids', 'type' =&gt; 'select', 'options' =&gt; dr_post_select_list(), 'std' =&gt; '' ) ) ); // some more stuff here, but the error is above and the code works when I make 'options' somethings hard-coded. } ?&gt; </code></pre> <p>I am trying to call <code>dr_post_select_list()</code> in the protected <code>$widget</code> array to dynamically generate a list of posts, but I get the error <code>Parse error: syntax error, unexpected '(', expecting ')'</code> in reference to the line with the <code>dr_post_select_list()</code> function in it. It's as if it doesn't recognize that it's a function.</p> <p>I've tried the function elsewhere and it works fine. I've tried making the array public and that doesn't change anything. I've tried saving the function output in an array and putting the variable in the array </p> <p>I get the sense that I'm doing something fundamentally wrong.</p> <p>tl;dr - method called in array in a class doesn't run (or seem to be recognized as a method).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload