GGG
January 26, 2023, 1:07am
#1
If there is a company in my company page on my site, but the job has already expired or they already found a person for their job, how can I make it so the company is hidden?
Because I can imagine a situation where there are a bunch of companies listed in my companies section of my site, but when a user clicks on it, it will just say “no results” because the job they posted already expired.
How can I hide the companies (in the companies section) that don’t have any active jobs available? And only show the ones which have an active job listing?
ihor
January 26, 2023, 9:47pm
#2
Sorry, there’s no such option in the current version, when the last listing of a company is expired or hidden the company profile is not hidden or deleted. We can try to provide a temporary code snippet for this, but it may require further customizations.
GGG
January 27, 2023, 3:24am
#3
Ok, yeah if you could provide a code snippet for this, that would be great.
Are there any plans to update the theme and make this a permanent feature of the theme? I think this would make the user experience a lot better.
Because I think it will be annoying for users to look in the companies section and keep clicking on company after company with no jobs.
There should be a way to only show the companies with a current job post.
andrii
January 27, 2023, 1:47pm
#6
Hi,
Thanks for your suggestion, we’ll consider adding this feature.
To show companies with current job posts, if I understand you correctly, please try these PHP snippets (replace “one, two, three” with the field names you want to keep in sync with the vendor fields):
add_action(
'hivepress/v1/models/vendor/update',
function( $vendor_id, $vendor ) {
// Check status.
if ( $vendor->get_status() !== 'publish' ) {
return;
}
// Set attributes.
$attributes = array_flip( [ 'one', 'two', 'three' ] );
// Get values.
$values = array_intersect_key( $vendor->serialize(), $attributes );
// Get listings.
$listings = HivePress\Models\Listing::query()->filter(
[
'status__in' => [ 'draft', 'pending', 'publish' ],
'vendor' => $vendor->get_id(),
]
)->get();
// Update listings.
foreach ( $listings as $listing ) {
if ( array_intersect_key( $listing->serialize(), $attributes ) !== $values ) {
$listing->fill( $values )->save( array_keys( $values ) );
}
}
},
10,
2
);
add_action(
'hivepress/v1/models/listing/update',
function( $listing_id, $listing ) {
// Get vendor.
$vendor = $listing->get_vendor();
if ( ! $vendor || $vendor->get_status() !== 'publish' ) {
return;
}
// Get attributes.
$attributes = array_flip( [ 'one', 'two', 'three' ] );
// Get values.
$values = array_intersect_key( $vendor->serialize(), $attributes );
// Update listing.
if ( array_intersect_key( $listing->serialize(), $attributes ) !== $values ) {
$listing->fill( $values )->save( array_keys( $values ) );
}
},
10,
2
);
1 Like
GGG
January 28, 2023, 1:21pm
#7
andrii:
add_action(
'hivepress/v1/models/vendor/update',
function( $vendor_id, $vendor ) {
// Check status.
if ( $vendor->get_status() !== 'publish' ) {
return;
}
// Set attributes.
$attributes = array_flip( [ 'one', 'two', 'three' ] );
// Get values.
$values = array_intersect_key( $vendor->serialize(), $attributes );
// Get listings.
$listings = HivePress\Models\Listing::query()->filter(
[
'status__in' => [ 'draft', 'pending', 'publish' ],
'vendor' => $vendor->get_id(),
]
)->get();
// Update listings.
foreach ( $listings as $listing ) {
if ( array_intersect_key( $listing->serialize(), $attributes ) !== $values ) {
$listing->fill( $values )->save( array_keys( $values ) );
}
}
},
10,
2
);
add_action(
'hivepress/v1/models/listing/update',
function( $listing_id, $listing ) {
// Get vendor.
$vendor = $listing->get_vendor();
if ( ! $vendor || $vendor->get_status() !== 'publish' ) {
return;
}
// Get attributes.
$attributes = array_flip( [ 'one', 'two', 'three' ] );
// Get values.
$values = array_intersect_key( $vendor->serialize(), $attributes );
// Update listing.
if ( array_intersect_key( $listing->serialize(), $attributes ) !== $values ) {
$listing->fill( $values )->save( array_keys( $values ) );
}
},
10,
2
);
Thank you so much. Should I input this code in this section:
Appearance —>Theme file editor ------> Theme functions
Is that the correct spot?
andrii
January 28, 2023, 3:09pm
#8
Hi,
Please try using the Code Snippets plugin for adding and managing custom PHP code snippets.