'Trying to get property 'ID' of non-object (and) Undefined index: listing_type
Trying to get property 'ID' of non-object (and) Undefined index: listing_type
if (!file_exists($upload['basedir'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css")) {
$style_url = $upload['baseurl']."/ulisting/css/".$css_file_name.".css";
} else {
$style_url = $upload['baseurl'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css";
}
Solution 1:[1]
Try to verify what is actually in $args. Make some simple dump above your lines of code
var_dump($args);die;
if (!file_exists($upload['basedir'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css")) {
$style_url = $upload['baseurl']."/ulisting/css/".$css_file_name.".css";
} else {
$style_url = $upload['baseurl'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css";
}
Solution 2:[2]
Not solved the full function is
public static function render($sections, $css_file_name, $args) {
$content = "";
$upload = wp_get_upload_dir();
if (!file_exists($upload['basedir'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css"))
{
$style_url = $upload['baseurl']."/ulisting/css/".$css_file_name.".css";
} else {
$style_url = $upload['baseurl'].'/ulisting/css/'.$args['listing_type']->ID.'/'.$css_file_name.".css";
}
wp_enqueue_style('ulisting_builder_stytle_'.$css_file_name, $style_url);
if(is_array($sections) AND !empty($sections)) {
foreach ($sections as $section) {
$content .= StmListingTemplate::load_template('builder/section',['section' => $section, 'args' => $args]);
}
}
return $content;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rafa? Rudowski |
| Solution 2 | jona303 |
