# Change the related listings query

**URL:** <https://community.hivepress.io/t/change-the-related-listings-query/10296>\
**Category:** HivePress\
**Tags:** code\
**Created:** [March 26, 2024, 11:29pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296 "2024-03-26T23:29:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![usedtoapp0](https://community.hivepress.io/user_avatar/community.hivepress.io/usedtoapp0/32/6552_2.png) [@usedtoapp0](https://community.hivepress.io/u/usedtoapp0)\
**Post date:** [March 26, 2024, 11:29pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/1 "2024-03-26T23:29:16Z")

</div>

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

```auto
.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.

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [March 28, 2024, 10:43pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/3 "2024-03-28T22:43:57Z")

</div>

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](https://hivepress.github.io/hook-reference/hivepress_v1_models_%257Bmodel_name%257D_relate.html)

Regarding the CSS, please try leaving only this selector:

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

```

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

---

<div class="post-metadata">

**Author:** ![usedtoapp0](https://community.hivepress.io/user_avatar/community.hivepress.io/usedtoapp0/32/6552_2.png) [@usedtoapp0](https://community.hivepress.io/u/usedtoapp0)\
**Post date:** [April 2, 2024, 9:12pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/4 "2024-04-02T21:12:03Z")

</div>

Hi,

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [April 3, 2024, 12:23pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/7 "2024-04-03T12:23:55Z")

</div>

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](https://www.w3schools.com/html/html_css.asp).

---

<div class="post-metadata">

**Author:** ![usedtoapp0](https://community.hivepress.io/user_avatar/community.hivepress.io/usedtoapp0/32/6552_2.png) [@usedtoapp0](https://community.hivepress.io/u/usedtoapp0)\
**Post date:** [April 3, 2024, 10:00pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/8 "2024-04-03T22:00:44Z")

</div>

> [@usedtoapp0](#):
>
> `'materia' => $listing->get_materia()`

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?

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [April 4, 2024, 10:45am UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/11 "2024-04-04T10:45:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![usedtoapp0](https://community.hivepress.io/user_avatar/community.hivepress.io/usedtoapp0/32/6552_2.png) [@usedtoapp0](https://community.hivepress.io/u/usedtoapp0)\
**Post date:** [April 4, 2024, 9:25pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/12 "2024-04-04T21:25:05Z")

</div>

I tried with the var\_dump() and it take the materia value, also using \_\_id(), but it seem not working with the matching.

```auto
if ( $listing->get_categories__id() ) {
				$query->filter(['categories __in' => $listing->get_categories__ id(),
    							'materia' => $listing->get_materia__id(), 
				]);
			}

```

Also tried with this

```auto
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.

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [April 5, 2024, 8:49am UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/15 "2024-04-05T08:49:56Z")

</div>

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](https://help.hivepress.io/article/75-how-to-add-listing-attributes)

Unfortunately, there is no package feature for requests.

---

<div class="post-metadata">

**Author:** ![usedtoapp0](https://community.hivepress.io/user_avatar/community.hivepress.io/usedtoapp0/32/6552_2.png) [@usedtoapp0](https://community.hivepress.io/u/usedtoapp0)\
**Post date:** [April 5, 2024, 12:53pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/16 "2024-04-05T12:53:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [April 24, 2024, 7:34pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/18 "2024-04-24T19:34:06Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [May 24, 2024, 7:34pm UTC](https://community.hivepress.io/t/change-the-related-listings-query/10296/19 "2024-05-24T19:34:38Z")

</div>

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