I have a classifieds site created with Wordpress and ACF, I created a Custom Post CLASSIFIEDS and a Taxonomy named "Main Category". I added in "Main Category" the various categories concerning the classifieds (Real esate, Job,...).
I created with ACF a field "Image Category" that I assigned to the "Main Category" Taxonomy, so I can add an image to each of the Princiaples Categories. My goal is to be able to display a grid with my different ads and to display the image of the main category in each ad card.
So I tried with function inside my functions.php :
function render_custom_field_image_block() {
// Object can be a post, term or user.
$object = wpgb_get_object();
echo ("VALUE :");
var_dump($object);
// If this is not a post (you may change this condition for user or term).
if ( ! isset( $object->post_type ) ) {
return;
}
// categorie_image is the field name about my category image field created with ACF
$image_id = get_post_meta( $object->ID, 'categorie_image', true );
if ( empty( $image_id ) ) {
return;
}
// You can change the image size "medium_large" to suit your needs.
$image_url = wp_get_attachment_image_url( $image_id, 'medium_large' );
if ( empty( $image_url ) ) {
return;
}
printf(
'<img src="%s" alt="%s" width="100%" height="250px" style="object-fit:contain">',
esc_url( $image_url ),
esc_attr( get_post_meta( $image_id, '_wp_attachment_image_alt', true ) )
);
}
But not working and the var_dump on $object don't contain info about categorie image except the ID of the categorie :
VALUE :object(WP_Post)#13417 (31) {
["ID"]=>
int(12593)
["post_author"]=>
array(4) {
["ID"]=>
int(1)
["display_name"]=>
string(10) "erikdenice"
["posts_url"]=>
string(45) "/author/erikdenice/"
["avatar"]=>
array(11) {
["size"]=>
int(96)
["height"]=>
int(96)
["width"]=>
int(96)
["default"]=>
string(2) "mm"
["force_default"]=>
bool(false)
["rating"]=>
string(1) "g"
["scheme"]=>
NULL
["processed_args"]=>
NULL
["extra_attr"]=>
string(0) ""
["found_avatar"]=>
bool(true)
["url"]=>
string(81) "https://secure.gravatar.com/avatar/635ba97b42d5681c19c4fc0f641bfa6e?s=96&d=mm&r=g"
}
}
["post_date"]=>
int(1666982551)
["post_date_gmt"]=>
string(19) "2022-10-28 16:42:31"
["post_content"]=>
string(14) "Vends cabinets"
["post_title"]=>
string(14) "Vends cabinets"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(14) "vends-cabinets"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
int(1666982551)
["post_modified_gmt"]=>
string(19) "2022-10-28 16:42:31"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(62) "/?post_type=pt-annonces&p=12593"
["menu_order"]=>
int(0)
["post_type"]=>
string(11) "pt-annonces"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
["object_type"]=>
string(4) "post"
["post_sticky"]=>
bool(false)
["metadata"]=>
array(21) {
["_edit_lock"]=>
string(12) "1666975261:1"
["_edit_last"]=>
string(1) "1"
["type_de_lannonce_Catégorie"]=>
string(2) "43"
["_type_de_lannonce_Catégorie"]=>
string(19) "field_63471b1906e2f"
["type_de_lannonce"]=>
string(0) ""
["_type_de_lannonce"]=>
string(19) "field_63471b1903469"
["cabinets_concerne_cab"]=>
string(2) "61"
["_cabinets_concerne_cab"]=>
string(19) "field_63471b192cb91"
["cabinets"]=>
string(0) ""
["_cabinets"]=>
string(19) "field_63471b190355e"
["ville_concernee_par_lannonce"]=>
string(5) "PARIS"
["_ville_concernee_par_lannonce"]=>
string(19) "field_634af425dbd97"
["le_prix"]=>
string(6) "350000"
["_le_prix"]=>
string(19) "field_634acfab8dcdd"
["personne_contacter_nom"]=>
string(0) ""
["_personne_contacter_nom"]=>
string(19) "field_63471b196156d"
["personne_contacter"]=>
string(0) ""
["_personne_contacter"]=>
string(19) "field_63471b190370e"
["autres_images"]=>
string(0) ""
["_autres_images"]=>
string(19) "field_63471b1903789"
["wpgb"]=>
array(17) {
["post_format"]=>
string(0) ""
["permalink"]=>
string(0) ""
["columns"]=>
int(1)
["rows"]=>
int(1)
["content_background"]=>
string(0) ""
["overlay_background"]=>
string(0) ""
["content_color_scheme"]=>
string(0) ""
["overlay_color_scheme"]=>
string(0) ""
["attachment_id"]=>
string(0) ""
["gallery_ids"]=>
string(0) ""
["mp3_url"]=>
string(0) ""
["ogg_url"]=>
string(0) ""
["mp4_url"]=>
string(0) ""
["ogv_url"]=>
string(0) ""
["webm_url"]=>
string(0) ""
["embed_video_url"]=>
string(0) ""
["video_ratio"]=>
string(4) "16:9"
}
}
["permalink"]=>
string(54) "/pt-annonces/vends-cabinets/"
["post_terms"]=>
array(2) {
[0]=>
object(WP_Term)#13411 (13) {
["term_id"]=>
int(43)
["name"]=>
string(8) "CABINETS"
["slug"]=>
string(8) "cabinets"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(43)
["taxonomy"]=>
string(20) "categorie_principale"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
["link"]=>
string(57) "/categorie_principale/cabinets/"
["color"]=>
string(0) ""
["background"]=>
string(0) ""
}
[1]=>
object(WP_Term)#13409 (13) {
["term_id"]=>
int(61)
["name"]=>
string(5) "VENTE"
["slug"]=>
string(5) "vente"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(61)
["taxonomy"]=>
string(12) "type_cabinet"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
["link"]=>
string(46) "/type_cabinet/vente/"
["color"]=>
string(0) ""
["background"]=>
string(0) ""
}
}
["post_format"]=>
string(8) "standard"
["post_media"]=>
NULL
}
So my question is how to get the URL of the categorie_image?
Related
I have a query like this :
$this->db->select('shop_users.user_id');
$this->db->select('users.*');
$this->db->from('shop_users');
$this->db->join('users' , 'users.id = shop_users.user_id' );
$this->db->where('shop_users.shop_id',$gets['shop_id']);
$user = $this->db->get()->result();
$data['user'] = $user;
var_dump($user);
return;
content of var_dump() is :
> array(1) { [0]=> object(stdClass)#76 (29) { ["user_id"]=> string(5)
> "33691" ["id"]=> string(5) "33691" ["username"]=> string(16)
> "" ["password"]=> string(32)
> "" ["name"]=> string(8) "سوده"
> ["family"]=> string(17) "Ù…Øمد کاشی" ["email"]=> string(21)
> "" ["avatar"]=> string(11) "default.gif"
> ["status"]=> string(1) "1" ["submit_date"]=> string(19) "2015-12-26
> 13:17:20" ["last_activity"]=> string(1) "0" ["activecode"]=> string(1)
> "0" ["submit_ip"]=> string(0) "" ["city"]=> string(1) "1" ["zone"]=>
> string(1) "0" ["city_name"]=> string(1) " " ["phone"]=> string(20)
> "" ["bankAcount"]=> string(13) ""
> ["bankCart"]=> string(1) " " ["bank"]=> string(1) " " ["admin_seen"]=>
> string(1) "1" ["gender"]=> string(1) " " ["finance"]=> string(1) "0"
> ["coupons"]=> string(1) "0" ["shaba"]=> string(1) " " ["ref"]=>
> string(1) "0" ["done"]=> string(1) "0" ["hasmobile"]=> string(1) "0" }
> }
now, how can I fetch user_id ?
I've test below codes but them return null:
$user->user_id;
$user['user_id'];
$user[0]['user_id'];
or
$user[0]->user_id;
You have to access to first element of your array because it is your array of returned values. (array in array)
You get a array from this query. You can get first item at frist and than get attrs of the item.
if($user && count($user)>0){
echo $user[0]->user_id;
}
when i write this query. i have a two records in shown in result
although the table has only one.
$side_messages = Message::orderBy('id' , 'desc')
->where('to_id' , Auth::id())->orWhere('from_id' , Auth::id())->first();
dd($side_messages);
The result:
object(Message)#412 (20) { ["fillable":protected]=> array(4) { [0]=> string(5) "to_id" [1]=> string(7) "from_id" [2]=> string(3) "msg" [3]=> string(4) "seen" } ["guarded":protected]=> array(0) { } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(7) { ["id"]=> string(1) "1" ["from_id"]=> string(1) "1" ["to_id"]=> string(1) "2" ["msg"]=> string(18) "test_query" ["seen"]=> string(1) "0" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["original":protected]=> array(7) { ["id"]=> string(1) "1" ["from_id"]=> string(1) "1" ["to_id"]=> string(1) "2" ["msg"]=> string(18) "test_query" ["seen"]=> string(1) "0" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) }
It's one value not two but it's repeated for some reason one for #attributes:[] and the other for #original:[]
first method return a single model instance (Illuminate\Database\Eloquent\Collection).
If you need to debug how much row is returned, you can use
$count = Message::orderBy('id' , 'desc')->where('to_id' , Auth::id())->orWhere('from_id' , Auth::id())->count();
I think the result your posted is an instance of your Message model. So you can't be sure that it's returning duplicate record.
first method always return single instance of model. Not collection (multiple record) of model instance.
This dump You post is a model object, so it contains all the model settings. The thing that is important is the section
object(Message)#412 (20) { ["fillable":protected]=> array(4) { [0]=> string(5) "to_id" [1]=> string(7) "from_id" [2]=> string(3) "msg" [3]=> string(4) "seen" } ["guarded":protected]=> array(0) { } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(7) { ["id"]=> string(1) "1" ["from_id"]=> string(1) "1" ["to_id"]=> string(1) "2" ["msg"]=> string(18) "test_query" ["seen"]=> string(1) "0" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["original":protected]=> array(7) { ["id"]=> string(1) "1" ["from_id"]=> string(1) "1" ["to_id"]=> string(1) "2" ["msg"]=> string(18) "test_query" ["seen"]=> string(1) "0" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) }
For much cleaner dump execute this:
$side_messages = Message::orderBy('id' , 'desc')->where('to_id' , Auth::id())->orWhere('from_id' , Auth::id())->first();
dd($side_messages->toArray());
And show me where is second object?!
I need to send data using ajax in Symfony2 action.
For this I use the following js code:
$.ajax({
type: "POST",
url: "{{ path('slch_create_slot',{ 'uuid': meeting.uuid })}}",
data: request,
cache: false,
success: function(){
alert(data);
location.href = "{{ path('slch_new_meeting_step2',{ 'uuid': meeting.uuid })}}";
}
});
Symfony2 side I use the following code:
if($request->isXmlHttpRequest()){
$json = $request->getContent();
$tableau = json_decode($json, true);
var_dump($tableau);
....
$response = new Response(json_encode(array('response' => 'ok')));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
When retrieving the Symfony2 response I get the following results:
array(1) {
["slots"]=>
array(4) {
[0]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "11"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[1]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "12"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[2]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "13"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
[3]=>
array(5) {
["hour"]=>
string(2) "14"
["minute"]=>
string(1) "0"
["day"]=>
string(2) "14"
["month"]=>
string(1) "1"
["year"]=>
string(4) "2015"
}
}
}
{"response":"ok"}
can you tell me why I have the request in the Symfony2 response ?
you're doing var_dump($tableau) which dumps the request. That's why you're receiving it. Get rid of that line and you won't receive it anymore. – acontell 1 hour ago
I have an peculiar session array variable,I need to pick one element to display on the screen.I'm not sure how to do that in smarty.Please give me the syntax how to manipulate the element in smarty.Here is the array values. I need to select ["school_name"] from the set.Please help
array(6) {
["id"]=> string(32) "cb60942f64d2b7bae2076926ae430f1d"
["sa"]=> NULL ["start_cache_timer"]=> int(1377752940) ["user"]=>
array(17) {
["host_id"]=> string(1) "9"
["user_id"]=> string(2) "16"
["school_name"]=> string(10) "Joseph High School"
["code"]=> string(10) "2E4C5339F8"
["academic_id"]=> string(2) "21"
["title"]=> string(2) "Mr"
["first_name"]=> string(3) "Jon"
["last_name"]=> string(7) "Bachura"
["name"]=> string(11) "Jon Bachura"
["email"]=> string(12) "jon#yeks.org"
["role"]=> string(1) "1"
["times_login"]=> int(656)
["acc_status"]=> string(1) "3"
["user_status"]=> string(1) "3"
["admin_user_id"]=>
string(2) "16"
["life"]=>
array(2) {
["current"]=>
int(1377756843)
["start"]=>
int(1377756843)
}
["training"]=>
array(1) {
["start_time"]=>
float(1377752946.14)
}
}
["mrole"]=>
NULL
["extAjaxSession"]=>
int(3)
}
Use $smarty.session:
$smarty.session.user.school_name
How do I access the price in one of the simple products? The following is the beginning of the array I want to access from my var_dump($_product->debug()); (stackoverflow wouldn't let me post the whole thing). I am working on the issue related to this post: Magento Retrieve simple product price for configurable product
["_cache_instance_products"]=>
array(9) {
["0 (Mage_Catalog_Model_Product)"]=>
array(33) {
["entity_id"]=>
string(2) "69"
["entity_type_id"]=>
string(1) "4"
["attribute_set_id"]=>
string(2) "10"
["type_id"]=>
string(6) "simple"
["sku"]=>
string(13) "1001-blu-ven1"
["has_options"]=>
string(1) "0"
["required_options"]=>
string(1) "0"
["created_at"]=>
string(19) "2013-04-02 22:12:27"
["updated_at"]=>
string(19) "2013-04-02 23:54:41"
["parent_id"]=>
string(2) "78"
["color"]=>
string(1) "6"
["vendor"]=>
string(1) "5"
["name"]=>
string(14) "test_1 blue v1"
["url_key"]=>
string(14) "test-1-blue-v1"
["msrp_enabled"]=>
string(1) "2"
["msrp_display_actual_price_type"]=>
string(1) "4"
["image"]=>
string(12) "no_selection"
["small_image"]=>
string(12) "no_selection"
["thumbnail"]=>
string(12) "no_selection"
["options_container"]=>
string(10) "container2"
["url_path"]=>
string(19) "test-1-blue-v1.html"
["weight"]=>
string(6) "0.0000"
["price"]=>
string(6) "1.0000"
["status"]=>
string(1) "1"
["visibility"]=>
string(1) "1"
["enable_googlecheckout"]=>
string(1) "1"
["tax_class_id"]=>
string(1) "0"
["is_recurring"]=>
string(1) "0"
["description"]=>
string(19) "test_1 blue v1 desc"
["short_description"]=>
string(19) "test_1 blue v1 desc"
I was able to get this question answered in the other forum: https://magento.stackexchange.com/questions/4050/access-price-variable-in-product-object/4051?noredirect=1#comment5583_4051
$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProducts(null,$_product);
foreach($childProducts as $child) {
print_r($child->getPrice());
}