traveler
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: add_meta_box (Will display only in specific page admin)Hey Niel, I’m not sure if you’ve used if or if/else statements to load custom scripts (css or js) on specific front-end pages (I do this quite often), but it’s the same idea. I would do a check to see what page is being loaded, use is_page() to test for what page you want that meta box on, if it’s not the page you want, just “return” so nothing runs. If it returns as true, meaning that it is the page you want, then register that meta box.
I’ve not done it the way bcworkz mentioned, so I am interested to know more of why it would be beneficial. I have a custom project with tons of meta boxes across different post types, bcworkz pointed me in the right direction for creating them all.
Forum: Developing with WordPress
In reply to: add_meta_box (Will display only in specific page admin)@bcworkz is this so you only have a single meta-box php file rather than say 4 different ones that all go on a different screen? So it’s easier to manage?
I’ve been getting the same issue for well over two months.
Hello bcworkz,
Thanks for your advice. I played around with what I had an got it to work although I’m not 100% sure why it worked. Here is a short version of the loop on the page, there are more taxonomies but this will give you an idea of the format I have:<!-- Query images attached to client --> <?php $imgArgs = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order', 'tax_query' => array( array( 'taxonomy' => 'client', 'field' => 'slug', 'terms' => $currentUser, ), ), ); $imgQuery = new WP_Query($imgArgs); if ($imgQuery->have_posts()) : ?> <div class="closet-all-items"> <?php global $post; $sleeveless = array(); $shortsleeve = array(); $longsleeve = array(); while ($imgQuery->have_posts()) : $imgQuery->the_post(); $imageId = wp_get_attachment_image_src(get_the_ID()); $taxonomy = 'clothing'; $imageTerm = get_the_terms(get_the_ID(), $taxonomy); // returns slug of taxonomy if ($imageTerm[0]->name == 'sleeveless') { $sleeveless[] = $post; } if ($imageTerm[0]->name == 'shortsleeve') { $shortsleeve[] = $post; } if ($imageTerm[0]->name == 'longsleeve') { $longsleeve[] = $post; } endwhile; wp_reset_postdata(); if ($sleeveless) { ?> <h5>sleeveless</h5> <div class="img-tax-section"> <?php foreach ($sleeveless as $post) { setup_postdata($post); $imageId = wp_get_attachment_image_src(get_the_ID()); ?> <div class="closet-item list-item"><img loading="lazy" class="<?php echo $currentUser; ?>" src="<?php echo $imageId[0] ?>"></div> <?php } ?> </div> <?php } if ($shortsleeve) { ?> <h5>shortsleeve</h5> <div class="img-tax-section"> <?php foreach ($shortsleeve as $post) { setup_postdata($post); $imageId = wp_get_attachment_image_src(get_the_ID()); ?> <div class="closet-item list-item"><img loading="lazy" class="<?php echo $currentUser; ?>" src="<?php echo $imageId[0] ?>"></div> <?php } ?> </div> <?php } if ($longsleeve) { ?> <h5>longsleeve</h5> <div class="img-tax-section"> <?php foreach ($longsleeve as $post) { setup_postdata($post); $imageId = wp_get_attachment_image_src(get_the_ID()); ?> <div class="closet-item list-item"><img loading="lazy" class="<?php echo $currentUser; ?>" src="<?php echo $imageId[0] ?>"></div> <?php } ?> </div> <?php } ?> </div> <?php else : echo '<p>There are no closet items yet.</p>'; endif; ?>Before your post I was using
foreach ($taxArray as $key) {...}but this did not work. I switched it to$taxArray as $postand it worked/output exactly how I wanted it to. However, if I comment outglobal $post;at the top of the array declarations, it continues to work usingforeach ($taxArray as $post) {...}.Why in this case would it only work with $post used instead of $key?
Am I using
global $post;wrong in the above loop? I’m not sure why it works without it based on your post above (admittedly, I’m not sure when to use global $post or when not to use it).Last, I’m creating the array declarations and taxonomy string declarations manually on the page. Would it be possible to dynamically call in the complete list of these taxonomy terms, store in an array, and then loop through that array to build the taxArray()’s, and then instead of building each section of output (these are the sections for sleeveless, shortsleeve, and longsleeve) manually could I also loop through the taxonomy array to build this? The goal would be so that if an admin adds a new taxonomy item to the list, it automatically adds that tax value and automatically would create the new taxArray() variable declaration, and also the section output?
Forum: Developing with WordPress
In reply to: wp_list_categories() by multiple custom taxonomy queriesI wanted to follow up on this, been busy on a different project, but in case anyone is following this thread for a similar reason I wanted to post my progress.
The ultimate goal is to have a dynamically created menu based off of a custom taxonomy for “clothing” that corresponds to a logged-in user and images attached to that logged-in user with the clothing taxonomy. So if a single user has 3 pairs of shoes (as images) attached to their profile, then this menu should show a link for “shoes” and take that user to a list/archive view of their images with that “shoes” tax.
My image query pulled in all of the images attached to a user/client’s page:
<?php $imgArgs = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'post_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'client', 'field' => 'slug', 'terms' => $currentUser, 'order' => 'ASC', 'orderby' => 'menu_order', ), ), ); $imgQuery = new WP_Query($imgArgs); if ($imgQuery->have_posts()) : $returnedTaxes = array(); while ($imgQuery->have_posts()) : $imgQuery->the_post(); // CHECKS IF IMAGE HAS CLOTHING TAX ASSIGNED // PREVENTS ERROR ON UNCATEGORIZED IMAGE if (get_the_terms( get_the_ID(), 'clothing' )): foreach ( get_the_terms( get_the_ID(), 'clothing' ) as $tax ): $taxName = $tax->name; $returnedTaxes[] = $taxName; endforeach; else: $returnedTaxes[] = 'uncategorized'; endif; endwhile; else : echo '<p>There are no closet items yet.</p>'; endif; wp_reset_postdata(); ?>This worked fine to pull in the images based on the $currentUser variable which pulls in the current logged-in user. Then for the images pulled in by the query, I first check if they have the “clothing” tax assigned to them, if a single image did not have a clothing tax assignment, it threw an error. For the images with assigned clothing tax’s, I pushed those into an array. For any potential image that is not assigned to the clothing tax, I pushed that to the same array using “uncategorized” as a temporary tax and to not throw an error.
Then I used a foreach loop to go through this array and separate them into key/value pairs which only returns the tax name of items assigned that tax that are attached to that client page. This was intentional, so if a client does not have any image assigned to the clothing tax, they will not see an option to visit an empty list feed for that tax item.
// BUILD LIST OF CLOTHING TAX TERMS foreach(array_count_values($returnedTaxes) as $key => $total): // $termLink = get_term_link($key, 'clothing'); // echo print_r($termLink); echo $key . ' ' . $total . '<br>'; endforeach;The above foreach loop is correctly returning the number of images assigned to the clothing tax and this particular user.
Now what remains is to add an active link to the tax terms that are rendered based on the image query, so that a client can open their “closet page” and see their clothing taxonomy of images, and essentially sort through his/her closet on their phone.
To do this, since there is not a default archive view for tax terms, my plan was to create a layout for the clothing tax, “taxonomy-clothing.php”, and use this to query images for a signed-in user that are attached to their client page and have the clothing tax. So if you have 300 sleeveless shirts, then in this menu you’d see a link for “sleeveless” and clicking it would take you to a tax list of “clothing-sleeveless” images. I would need a way to populate the specific tax term in the query dynamically based on the link clicked.
My question would be, do you recommend the above approach I’ve taken or would you advise I go about it differently. Two, to create the taxonomy links to view all “sleeveless” or all “boots”, does the plan above make sense for this? Any recommendation on dynamically populating the tax query term like “sleeveless” or “boots”?
Forum: Developing with WordPress
In reply to: wp_list_categories() by multiple custom taxonomy queriesHello Joy, thank you for clearing that up for me!
Forum: Developing with WordPress
In reply to: wp_list_categories() by multiple custom taxonomy queriesHey bcworkz, thanks for your reply. To clarify, the images being queried are saved to an ACF image gallery field on the client’s page. Is that what you mean by “I assume the terms are assigned to image attachment posts”?
So I abandoned the approach I had outlined above and instead went back to query all images attached to that client’s page through the ACF gallery. The query is returning the correct images. So then I did a var_dump($imgQuery) to see what all was returned. I should note, this is the first time I’ve viewed a query like this so most of it made sense but it seemed like a lot of things were repeated throughout. But, the point is, the correct images were returned and looking at the query behind it the image IDs were correct and post_parent also returned the correct post/client parent.
In theory what you said above makes sense, but looking at the returned data I do not see any mention of the custom tax that is attached to the media attachments. My thoughts were to take the returned image IDs and use that to pull the assigned taxonomy, but I did not see a WP function that would take an image ID and return it’s assigned taxonomy. But, I do not see a WP function that does that unless I’ve read through the documentation and not fully understood it.
Can you please point me in the direction of what I need to pull the assigned tax for the images? Ideally, once the assigned custom tax for each image is procured, I’d like to push them into different arrays (if assigned “shoes” taxonomy, it’s pushed to shoeArray().
Here is a sample of the returned image loop that is returning the correct images:
public 'posts' => array (size=6) 0 => object(WP_Post)[2262] public 'ID' => int 241 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:48' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:48' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_sunglasses' (length=29) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_sunglasses' (length=29) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:29:48' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:29:48' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_sunglasses.jpg' (length=90) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) 1 => object(WP_Post)[2235] public 'ID' => int 242 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:48' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:48' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_top_hat' (length=26) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_top_hat' (length=26) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:29:35' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:29:35' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_top_hat.jpg' (length=87) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) 2 => object(WP_Post)[2265] public 'ID' => int 239 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:47' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:47' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_shirt-1' (length=26) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_shirt-1' (length=26) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:29:06' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:29:06' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_shirt-1.jpg' (length=87) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) 3 => object(WP_Post)[2266] public 'ID' => int 240 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:47' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:47' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_shoes-1' (length=26) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_shoes-1' (length=26) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:29:12' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:29:12' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_shoes-1.jpg' (length=87) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) 4 => object(WP_Post)[2267] public 'ID' => int 237 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:46' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:46' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_jacket-1' (length=27) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_jacket-1' (length=27) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:28:06' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:28:06' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_jacket-1.jpg' (length=88) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) 5 => object(WP_Post)[2316] public 'ID' => int 238 public 'post_author' => string '2' (length=1) public 'post_date' => string '2020-10-08 01:27:46' (length=19) public 'post_date_gmt' => string '2020-10-08 01:27:46' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'johnny-firstperson_pants-1' (length=26) public 'post_excerpt' => string '' (length=0) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'closed' (length=6) public 'ping_status' => string 'closed' (length=6) public 'post_password' => string '' (length=0) public 'post_name' => string 'johnny-firstperson_pants-1' (length=26) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2020-10-08 01:28:57' (length=19) public 'post_modified_gmt' => string '2020-10-08 01:28:57' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 216 public 'guid' => string 'http://closetleesaevans.local/wp-content/uploads/2020/10/johnny-firstperson_pants-1.jpg' (length=87) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3)Forum: Developing with WordPress
In reply to: wp_list_categories() by multiple custom taxonomy queriesHello Joy,
Thanks for your response. So, perhaps I’m reading the documentation incorrectly, but going to the wp_list_categories link above in your response, the first list item under args reads like this function can accept other parameters like get_categories, get_terms, or WP_Term_Query.So in the documentation, when a function says additional arguments can be added like other linked functions, am I interpreting that wrong? I see it on a lot of function pages in the docs..
Since images are a post type, can’t they be queried in the same manner with multiple tax_query’s?
Forum: Developing with WordPress
In reply to: Admin plugin to select images from media galleryThanks bcworkz, I appreciate your advice. I had not thought about a two button trigger system but that would make it easier I think.
Forum: Developing with WordPress
In reply to: Admin plugin to select images from media galleryHey bcworkz, thank you for clarifying that.
Yes, you are correct, a single post would be created to hold the selected images (6-8 images selected at a time). The images will be added to the ACF gallery for each client post, and also using the ACF gallery feature that only allows you to select images that were uploaded to the client’s post to keep client image galleries separate.
The post containing the images, if this post is not yet created thus no post ID exists, the Ajax call to wp_insert_post() will automatically create the new post ID, correct?
So the workflow would be:
1. create client closet
2. add images to ACF gallery field in the client closet post
3. use the ACF image field, there would need to be 8 total (6-8 img/new post) to select the images
4. have a jquery listener set up to grab the image ID, the current client post ID, and send it in an Ajax call to the server
5. receive the data from the Ajax call and process it with wp_insert_post()
6. add a callback function to hook into the new post being created to issue alerts to the admin, perhaps as simple as a js popup, and also initiate a system email to the clientDoes that seem about right?
Questions:
1. would you suggest using the ACF gallery field and the ACF image field for this function, or would you go about it in a more custom fashion and not use those fields?My goal is to create this so that the admin can work almost exclusively within the client closet post to create/select the images and create a new post of a different post type. It’s a stylist’s website, the clients essentially purchase outfit planning and the “outfits” will be the other post type that is created with the images. So a single outfit would contain 6-8 images (shoes, pants, shirt, jacket, bag, hat, belt, jewelry).
So ideally the admin would go to a client’s closet post, upload that clients images and tag them so they belong to that client post (post title is client name), and then from within that client’s closet go through the added images and create the outfits. My goal is to make this as intuitive as possible. Also, despite the direction I’ve gone with it so far, if you would recommend going about it in a different way I’d love to hear your advice.
Thanks.
- This reply was modified 5 years, 7 months ago by traveler.
Forum: Developing with WordPress
In reply to: How to send data from one page to a contact formmridulmet, what I described would not be a multi-level form, it’s actually 3 forms working together and “passing variables” to the next form that will then capture those variables. Most forms allow html blocks to be inserted so you can put an image(s) in a custom html block and use a radio selection to select a specific image. It’s hard to visualize the page you want without more details.
The other way which would remove the extra forms, would require you to include the URL or custom UTM parameters at the end of the link that you put around each image. So, if you have 2 images tags each with an href element around it, and they need to direct to the form page:
<a href="www.site.com/link-to-next-page?phone_selected=samsung"><img src="#" /></a>Then in the form page, you’d need to set up a hidden field (most forms have these standard) and you’ll look for an option to auto-populate the hidden field, and you’ll check that/turn that feature on and tell it to look for the parameter of “phone_selected” and put it’s value into the hidden field. The site user won’t ever see that additional code unless they look at the address bar in the browser, but if it’s set up correctly your form will include that parameter value that you passed in the URL string.
Forum: Developing with WordPress
In reply to: How to send data from one page to a contact formI should add, I altered my response above after saying use Javascript to adjust the URL. Using URL/UTM parameters to pass values between pages is common but does not require you to write custom Javascript if you are using a form that already allows you to pass variables/field values between forms on submit.
Forum: Developing with WordPress
In reply to: How to send data from one page to a contact formYou can use Javascript to adjust the URL that is ultimately sent to the form so that it contains custom UTM parameters to show their selection. There are a few ways you could do this, almost as George mentioned, you could set this up a multi-form system with redirects.
For exampmle, first form:
-single field for selecting the phone model
-on “continue (submit), attach the users selection as a URL parameter that is sent to the next page, it will be whatever you set up, so, “www.site.com/?phone_model=selection
– redirect the user to the next form page where they select the service.Second form:
-similar to above, but I would create a field to capture the previous value so that it loads wehn this 2nd form loads.
-So this form would have 2 fields, the first would capture the value selected from the URL from the first form. The 2nd would capture the service selection
-create custom UTM parameters for the new field, and whereas before you passed a single value through the URL redirect, this time you’ll pass 2 through to the last form.Third form:
-capture the values from the first two forms, and add the new fields needed.Keep in mind, form 1 is a single page with a single form, form 2 is a single page with a single form, and form 3 is a single page with a single form.
I’m not familiar with your particular form plugin, but it should allow you to send field values as URL parameters and also to capture from the URL those values in a new form.
Forum: Developing with WordPress
In reply to: Custom image uploader for cpt and force taxonomy attachmentThanks bcworkz, this was great info!
Forum: Developing with WordPress
In reply to: Custom image uploader for cpt and force taxonomy attachmentThanks bcworkz.
The relationship you describe above, when a relationship is established between the page being edited and the images uploaded with that page open, wouldn’t that parent property with the page ID of where they were uploaded be changed if that same image were used in a different page?
Would this behavior be different between using the gutenberg image field to upload and image vs using the ACF image gallery upload field?
Any way to make the relationship permanent between an uploaded image and the parent property page ID, so that it can’t be overwritten?
Do you know where I can find more information on the different attachment properties that mentioned above, and how would you query them by this attachment?