Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get the value of an php array key to display
    primarykey
    data
    text
    <p>Hello I am working on a wordpress theme and whan't a function to return the information of the last published post. my function so far:</p> <pre><code>function get_last_post() { $latest_post = new WP_Query("post_type=post&amp;posts_per_page=1&amp;orderby=date&amp;order=DESC&amp;post_status=publish"); if($latest_post-&gt;have_posts()) { reset($latest_post); $cur = current($latest_post); var_dump($cur); //var_dump($cur['']); $ret['title'] = $cur['post_title']; $ret['content'] = $cur['post_content'];; $ret['link'] = get_permalink($cur['ID']); } else { $ret['title'] = _e('Ni objav', 'responsive'); $ret['content'] = _e('ni novih objav', 'responsive'); $ret['link'] = ''; } return $ret; } </code></pre> <p>The problem is that I can't get the information from the array. I know total newbish but bare with me I am relatively new to php and I don't do it often.</p> <p>if I var_dump the array <code>var_dump($cur);</code> the information I whan't is there but can't seem to be able to grab it if I do <code>var_dump($cur['post_title'])</code> it returns <code>NULL</code> also I didn't find anything usefull on this on the web.</p> <p>Hope you guys can help.</p> <p><strong>The solution:</strong></p> <pre><code>function get_last_post() { $latest_post = new WP_Query("post_type=post&amp;posts_per_page=1&amp;orderby=date&amp;order=DESC&amp;post_status=publish"); if($latest_post-&gt;have_posts()) { $cur = $latest_post-&gt;posts; $cur = $cur[0]; $ret['title'] = $cur-&gt;post_title; $ret['content'] = $cur-&gt;post_content;; $ret['link'] = get_permalink($cur-&gt;ID); } else { $ret['title'] = _e('Ni objav', 'responsive'); $ret['content'] = _e('ni novih objav', 'responsive'); $ret['link'] = ''; } return $ret; } </code></pre>
    singulars
    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