I am using two types of custom posts- Company and Job and they are related in one to many way format.
I use one image custom field in Company and display the same in related job posts too. I want to use this 'image of company' as a 'featured image of the job'. I am closely following instructions given in this solution (used for another purpose) provided at https://toolset.com/forums/topic/affect-an-image-field-as-featured-image-for-a-product/
But I couldn't make out the same though I have fetched the image.
For the purpose I am sharing two URLs to see the things: hidden link (job post) hidden link (company post)
Please help me to get the desired result. Thanks
Hi,
I am creating the child in the backend.
I am using Toolset Types and Toolset views plugin to generate the results.
For better clarification, you may have access to the admin page.
You can provide the admin access in the private reply that I will be enabling.
What I'm saying is that instead of copying over the Parent's featured image, you can load the parent's Featured image directly from the child template because we will have access to the parent's data.
Please let me know what you think of this solution, as copying over the parent post type image will require the use of custom coding.
I've edited the content template to include this line here
[types field='company-image' title='%%TITLE%%' alt='%%ALT%%' size='full' item='@company-job.parent'][/types]
This will pull the parent image of the current job. Secondly I can understand why you would want to do this but it you will need to go through and update the posts one by one.
You can use a hook to copy over parent image field to the featured image field, however when you are doing this you will need to go through each post one by one and hit the update button, which is just a little faster than manually adding the images.
I understand your point. You can use a hook to copy over parent image field to the featured image field, however, when you are doing this you will need to go through each post one by one and hit the update button, which is just a little faster than manually adding the images.
But how to create a hook. Please help.
Create a view that is listing out all the jobs and add the following to the loop section of the view [set_child_featured_Image]
Then add the view to a page and visit that view. It should loop through and automatically update all the posts with their respective parent featured image.
Hi Shane,
Thanks for your support. As I have seen you have already created the custom code 'test' which I have inserted in a newly created view called 'Job Image View' (ID 31629).
Then I placed the view in the job template (single) in line no. 5. Now?
The images are not showing up either in the post or while sharing on Facebook. Or maybe I am getting what you are suggesting.
Were you able to resolve the issue where the images weren't showing up on the Posts? From what I can see here in the link below they are now showing up. hidden link
If you are still having issues with this please let me know.
Secondly with the sharing of the post to facebook you will need to open a second ticket for this, however try this below. hidden link
This is meant to pull and display the parent image on the child post.
Given that we have copied over the images to the child post then you no longer need this specific shortcode. What you need to do now is to change it to [wpv-post-featured-image] and your images should display from the Job post itself.
Please let me know if this clears things up for you.
Well Shane, what I am able to understand that we don't need that custom shortcode created by you as it has copied the entire images of the parent post in child post. Hence I deactivated it and pasted the [wpv-post-featured-image] in the child post which is perfectly fetching the parent image as the featured image of the child post.
Will it work for future posts even if I keep it deactivated?
Now for the second part i.e. sharing the same child featured image in FB and Twitter you are suggesting to open a new ticket. If you resolve the same for me I'd be immensely happy. Meanwhile, I have gone through your suggested link. It's suggesting about Yoast which I am already using (but doesn't help much as I have to choose every image for the post). What I want is to automatically add the featured image (with OG tag) while posting Facebook/Twitter.
Here I read a solution but couldn't help. https://wordpress.stackexchange.com/questions/159162/set-custom-post-feature-image-as-ogimage
Given that we've copied over all the existing image, we can then convert this shortcode to a hook that will fire each time a new child post is created.
function set_child_featured_image($post_id) {
// If this is a revision, get real post ID
if ( get_post_type($post_id) == 'job' )
$child = $post_id;
$parent = toolset_get_related_post( $child, "company-job" );
$featured = get_post_meta($parent,'wpcf-company-image');
set_post_thumbnail($child,attachment_url_to_postid($featured[0]));
}
}
add_action( 'save_post', 'set_child_featured_image' );
Please add this to your custom functions and activate it. Ensure that the Backend option is checked when you are adding the code to the Toolset custom code section.
Given that the Facebook issue is separate from this one then you will need to open a new ticket. It helps to keep our forums organised and assist other users who are experiencing a similar issue. I hope you can understand this.