Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
901 stars 368 forks source link

Make WPJM's CPTs more accessible for page builders? #1613

Open jenhooks opened 5 years ago

jenhooks commented 5 years ago

A user in this forums thread wants to create custom listing pages using a page builder like Elementor. However, they note that while Elementor has the ability to "bring dynamic data through", WPJM's custom fields seem to be inaccessible.

Elementor support has advised that everything needs to be set to (‘public’ => true) and has_archive should also be set to true. They cite this documentation:

https://elementor.com/blog/wordpress-custom-post-types/

Elementor support recommended we contact them directly on GitHub to work out compatibility, if this is something we'd like to pick up in the future.

richardmtl commented 5 years ago

1781186-zen

hsk-it commented 5 years ago

Any news on this?

richardmtl commented 5 years ago

@hsk-it No; if there was, you'd see it here. :)

itsdanprice commented 5 years ago

Is this looking at being added? It's a bit of a deal breaker for us at the moment in terms of getting a premium license.

gaurav1984 commented 5 years ago

1817102-zen

gfdesign commented 5 years ago

Any advanced with this issue? I don't see WPJM be compatible with Elementor :(

althaidi commented 5 years ago

Any plans to implement this? It's a major deal breaker of buying a license.

jom commented 5 years ago

For the archive page, that is enabled if current theme supports job-manager-templates. I doubt we'll be change that requirement, but you just need to declare support for it in your theme (https://wpjobmanager.com/document/enabling-full-template-support/).

For the meta fields, follow the issue #1697. That issue could replace this one, but I'll keep it open for now just to track any other conflicts/requirements with Elementor.

ethanclevenger91 commented 5 years ago

@jom while declaring theme support enables the archive to exist in general, it doesn't seem to make the archive accessible to Elementor when creating Archive theme templates. Can you confirm this?

jom commented 5 years ago

I'm not sure about third-party issues, but after you declare theme support, make sure you re-save your Permalinks in WP admin. For that archive page, we do it in a pretty standard way so I'm not sure how else that plugin would sniff for it.

ethanclevenger91 commented 5 years ago

Tracked this down. For whatever reason, Elementor Pro starts with the following query to find post types with valid archives:

array ( 'show_in_nav_menus' => true, )

WP Job Manager doesn't match that by default. The function is in their utils.php file and is called get_public_post_types, so you'd think they'd look for 'public' => true instead, but what do I know.

I'll be filtering the WP Job Manager post type registration args for now, and that may be the long-term solution if altering the post type query on Elementor's end doesn't make sense to them.

Elementor Pro 2.4.5, FWIW. To make it work:

add_filter('register_post_type_job_listing', function($args) {
    $args['show_in_nav_menus'] = true;
    return $args;
});
ethanclevenger91 commented 5 years ago

@pojome on the above

ethanclevenger91 commented 5 years ago

Further update, when it comes to custom fields:

Elementor Pro specifically filters out any meta keys that begin with an underscore:

if ( '_' !== substr( $custom_key, 0, 1 ) ) {
    $options[ $custom_key ] = $custom_key;
}

Which is...most WP Job Manager meta keys (by default). This is why they don't appear in the dropdown in Elementor's theme builder.

Joe-Bloggs commented 5 years ago

OMG @ethanclevenger91 you're a legend!

I've added the filter above and the listing custom post type is now showing in the Elementor template selection dropdown. Awesome.

Quick question regarding the second bit of code just above from 21 Mar, should I be also adding this string or any other code to enable the custom fields?

ethanclevenger91 commented 5 years ago

@Joe-Bloggs With the custom fields, you're actually kind of SOL. WP Job Manager prefixes its meta keys with underscores, which is WordPress core's de facto way of marking keys "private" (for example, underscore-prefixed keys don't appear in the post edit meta fields metabox).

Moving away from that via a migration in a later version of WP Job Manager is probably possible, though has a high potential of breaking BC, and is therefore unlikely. The next option would be if they added some kind of white-list filter in Elementor that allowed you to give it an array of meta keys to explicitly fetch. Not a bad idea, actually. @KingYes might be someone who can advocate for something like that. I may cross-post an issue to the Elementor repo.

rensvis commented 5 years ago

@ethanclevenger91 Did you actually manage to make this work?

gferguson1815 commented 5 years ago

Tracked this down. For whatever reason, Elementor Pro starts with the following query to find post types with valid archives:

array ( 'show_in_nav_menus' => true, )

WP Job Manager doesn't match that by default. The function is in their utils.php file and is called get_public_post_types, so you'd think they'd look for 'public' => true instead, but what do I know.

I'll be filtering the WP Job Manager post type registration args for now, and that may be the long-term solution if altering the post type query on Elementor's end doesn't make sense to them.

Elementor Pro 2.4.5, FWIW. To make it work:

add_filter('register_post_type_job_listing', function($args) {
    $args['show_in_nav_menus'] = true;
    return $args;
});

Where does the above code actually get placed?

richardmtl commented 4 years ago

@gferguson1815 I haven't tested, but I presume it would work if you added it to your functions.php, a custom plugin, or even easier, by using https://wordpress.org/plugins/code-snippets/

ethanclevenger91 commented 4 years ago

If you'd rather not change how WP Job Manager registers its post types (my originally proposed solution) and avoid potential unexpected behavior there, it looks like you can also use an Elementor filter to achieve exposing the Job Listing post type:

add_filter( 'elementor_pro/utils/get_public_post_types', function($post_types) {
    $jobs_cpt = get_post_type_object('job_listing');
    $post_types['job_listing'] = $jobs_cpt->label;
    return $post_types;
} );
vidhu12 commented 4 years ago

@ethanclevenger91 The solution that you have put up works perfectly! Kudos to you, keep up the good stuff!

cena commented 3 years ago

3961572-zen

cestrian77 commented 3 years ago

@ethanclevenger91 thanks so much for posting this snippet. Works perfectly!

sarahrileydev commented 3 years ago

@ethanclevenger91 Thank you, thank you for sharing your solution!

Archandan35 commented 3 years ago

If you'd rather not change how WP Job Manager registers its post types (my originally proposed solution) and avoid potential unexpected behavior there, it looks like you can also use an Elementor filter to achieve exposing the Job Listing post type:

add_filter( 'elementor_pro/utils/get_public_post_types', function($post_types) {
    $jobs_cpt = get_post_type_object('job_listing');
    $post_types['job_listing'] = $jobs_cpt->label;
    return $post_types;
} );

where i will used this code to show the custom field in elementor?

is i use in the wordpress function.php or anywhere else ?

jinnypark commented 2 years ago

4542809-zen:

I have noticed that there is a conflict with the jobs listing page when Elementor Pro is active. It appears that the formatting for the job listings is broken. Elementor Pro is one of the most popular plugins on wordpress and is important to my site however I would love if the job listings appeared correctly.

jinnypark commented 2 years ago

https://wordpress.org/support/topic/elementor-template-broken/

bizanimesh commented 2 years ago

Compatibility request - Elementor.

bizanimesh commented 2 years ago

5490671-zd-woothemes - Elementor.

bobmatyas commented 2 years ago

5577731-zen - Similar issue with Avada

github-actions[bot] commented 2 years ago

Support References

This comment is automatically generated. Please do not edit it.

cestrian77 commented 1 year ago

If you'd rather not change how WP Job Manager registers its post types (my originally proposed solution) and avoid potential unexpected behavior there, it looks like you can also use an Elementor filter to achieve exposing the Job Listing post type:

add_filter( 'elementor_pro/utils/get_public_post_types', function($post_types) {
    $jobs_cpt = get_post_type_object('job_listing');
    $post_types['job_listing'] = $jobs_cpt->label;
    return $post_types;
} );

Appreciate this post is old now... but with PHP8 being mandated by our web hosts, when we update the PHP version this particular code snippet is now causing a problem (that stops single job posts being displayed on the front end. Removing the code snippet then impacts our ability to style the job posts too). Is that coincidence, or does this need to be updated to work with PHP8 please?

hmbashar commented 1 year ago

It's Working for me and I think it should be working another way but I didn't check because the first way working. so if anyone doesn't match with the first way then try this second way Enabling Full Template Support

bobmatyas commented 1 year ago

5837181-zen for Elementor support

bobmatyas commented 1 year ago

6171331-zen citing lack of Elementor support for cancellation

keepkalm commented 1 year ago

All this plugin really needs to work is for Elementor to change one line in their post type declaration: https://github.com/Automattic/WP-Job-Manager/blob/a2fbcb2f68734e2ec672f810786f20a38a4670d6/includes/class-wp-job-manager-post-types.php#L375

'show_in_nav_menus' => false,

Set it to true and you can use Theme Builder now. You still need to go into Elementor settings to use the page builder for the jobs post type. IDK why it was set to false, default is true. If the answer is to sell plugins I think that is the wrong reason.