This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

149health

  • ***
  • 51 posts
Hello, MB themes
I have encountered an issue with the osclasspay plugin when the "Pay per Post" feature is enabled.
The Problem:
When a user fills out and submits a listing but does not complete the payment, a "slot" for listings disappears from the homepage. Even though the unpaid listing is not visible, it still seems to be counted in the query.
Example:
• If the homepage is set to display 16 latest listings and there is 1 unpaid listing, only 15 listings are actually displayed.
• If there are 2 unpaid listings, only 14 are displayed, and so on.
Requested Fix:
Listings should only be included in the display loop/query if they have been successfully paid for. This will ensure that the homepage always shows the full number of visible listings regardless of any pending payments.
Thank you for your attention!

*

MB Themes

Re: Issue with unpaid listings occupying slots in the display loop
« Reply #1 on: April 13, 2026, 11:31:01 AM »
latest listings should have filter on b_active = 1 and upaid listing should have b_active = 0, can you verify?
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

149health

  • ***
  • 51 posts
Re: Issue with unpaid listings occupying slots in the display loop
« Reply #2 on: April 14, 2026, 06:35:58 PM »
In short... I tried to fix it and ended up breaking everything. Rolled it back. :D
Claude AI says:
Cause of the bug:

Quote
The del_random_items() function in the theme's functions.php builds its own SQL subquery with LIMIT N, completely bypassing Osclass’s standard mechanism (the search_conditions hook).
The osclass_pay plugin attaches the unpaid listings filter to this exact hook (osp_item_filter), which is why its filter is never applied to the main page query. As a result, an unpaid ad gets into the LIMIT 16, occupies a slot, but isn’t displayed — which is why positions are disappearing.
Note: Setting b_active = 0 for unpaid ads should exclude them from the results — and it works correctly in normal searches. However, del_random_items() builds its own subquery that includes b_active = 1 but has no filter at all for t_osp_item.i_paid. Therefore, in publish_item_disable = 0 mode (when the item stays active but should be hidden until payment), it slips through.

So that’s the bug. Have a great day! :D

Marked as best answer by frosticek on April 17, 2026, 09:33:27 AM
*

MB Themes

Re: Issue with unpaid listings occupying slots in the display loop
« Reply #3 on: April 16, 2026, 10:21:43 AM »
Try this

in index.php of osclass pay add:
Code: [Select]
function osp_search_exclude_unpaid_filter($where = '', $item_table_alias = null) {
  if(osp_param('publish_allow') != 1) {
    return $where;
  }
 
  $item_table_alias = ($item_table_alias === null ? DB_TABLE_PREFIX.'t_item' : $item_table_alias);
  $paid = osp_param('publish_item_disable') == 1 ? 0 : 1;
  $cond = sprintf("EXISTS (SELECT 1 FROM %st_osp_item as ospx WHERE ospx.i_item_id = %s.pk_i_id AND ospx.s_type = '101' AND coalesce(ospx.i_paid, 0) = %d)", DB_TABLE_PREFIX, $item_table_alias, $paid);
 
  $where = trim((string)$where);
 
  return ($where == '' ? $cond : $where .' AND ' . $cond);
}

osc_add_filter('custom_item_search_conditions', 'osp_search_exclude_unpaid_filter');

in delta functions.php , before this block:
Code: [Select]
  if($withPicture) {
    $prem_where = ' AND ' . $whe;

add:
  $whe = osc_apply_filter('custom_item_search_conditions', $whe);
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots