Change the related listings query

I need to change the display of “similar listing” from category to an attribute that I created.

I also want to style the “PayOut Request button” with this code

.hp-payout__action .hp-payout__action--request .hp-link{
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    padding: 0.5rem 1rem;
    color: #fff;
    background-color: #8421e0;
    text-align: center;
}

to look like a real button but It doesn’t work. Also if I try from inspection it replicate the style over the username.

It’s possible to alter the related listings query, but this requires customizations using this hook Action: hivepress/v1/models/{model_name}/relate | HivePress Hook Reference

Regarding the CSS, please try leaving only this selector:

.hp-payout__action--request {
...styles here
}

You can also try adding !important at the end of the styles if they are not applied.

Hi,

for the query I’ve tried this in different ways but it doesn’t work

if ( $listing->get_categories__id() ) {
				$query->filter(['categories__in' => $listing->get_categories__id(),
    							'materia' => $listing->get_materia(), 
				]);
			}

with materia that is the field name of the attribute.

Also for the css it doesn’t work, nothing happen when I try to use only that selector and the style. I would like to make it more like a button.

Hi,

It all depends on the type of the materia attribute, if it’s a select attribute, then you also need 2 underscores and an ID, for example __id(), because just get_material will return an array of objects.
As for CSS, we can only provide general guidance. If the styles don’t work at all, we recommend using Web Inspector, 1 clear selector is enough, if you list several with a space, it will not work HTML Styles CSS.

Materia is a text area attribute that must be compile by a user when he is publishing a new listing. What should I add to that code for showing the releted listings with the subject and not only the category?

Hi,

If it is a text attribute, then everything should work correctly. Please try to debug this using var_dump or error_log to check the values in get_material and others. Also, please note that we can only provide general recommendations regarding custom code.

I tried with the var_dump() and it take the materia value, also using __id(), but it seem not working with the matching.

if ( $listing->get_categories__id() ) {
				$query->filter(['categories__in' => $listing->get_categories__id(),
    							'materia' => $listing->get_materia__id(), 
				]);
			}

Also tried with this

if ( $listing->get_categories__id() && $listing->get_materia__id() ) {
				
				$query->filter(['categories__in' => $listing->get_categories__id()], ['materia' => $listing->get_materia__id()]);

			}

This query should return all the listings that are in the same category and with the same materia…am I wrong? It only match the category in both version

I have other two questions:

I am interested in buying the request plugin and i would like to know if is it possibile to add custom attributes like the phone number and if that attributes can be use as a filter for searching.

The second question reguard using paid listing with the request plugin to ask the user to pay a monthly fee to keep their request online with the packages.

thanks.

Hi,

Please try debugging using $query->set_args(), there, you can set the default wp_query parameters and check if the query responds at all.

Yes, you can use the custom attribute filterable for requests, but please note that not all attributes will have this feature, you can test it with the listing attributes before buying, as there is similar functionality for this feature: How to add listing attributes - HivePress Help Center

Unfortunately, there is no package feature for requests.

Hi,

I tried to use$query->set_args(['categories__in' => $listing->get_categories__id(), 'materia' => $listing->get_materia__id()]) but now doesn’t match both category and materia…

Using the code with query->filter(…) and var_dump with categorie__id and materia__id it return and Array and a String.

So is there a way that a request after a monthly period of time, for example, is no longer visible and the user has to pay to renew it, as if it were a subscription?

Sorry for the delay.

I recommend debugging the custom code using error_log and var_dump. If you provide an array of IDs to categories__in using the default ->filter() method of a query, it will be altered for sure. If you use ->set_args() then you have to use the default WordPress API https://developer.wordpress.org/reference/classes/wp_query/#parameters

This way you can check if the method returns any category IDs, or attribute option IDs, or the issue is with the query, etc.

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.