Advertisement:

Author Topic: Limiting number of postings per user (solved)  (Read 1411 times)

BritWeb

  • Hero Member
  • *****
  • Posts: 770
  • If it ain't broke, don't fix it.
Limiting number of postings per user (solved)
« on: October 20, 2016, 12:07:03 am »
Hi

Is there a way to limit number of postings per user? Ideally I do not want an Estate agent to post every one of his property listings.

I would like to limit the number of listings to two for a member.

Thanks
« Last Edit: October 23, 2016, 02:52:09 pm by BritWeb »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Limiting number of postings per user
« Reply #1 on: October 20, 2016, 06:06:27 am »
***CORRECTED***

Hi,

Well, first you need to tick "Only logged in users can post listings" on Admin Dashboard / Listings / Settings.

Then insert this almost at the top of your theme item-post.php (after the initial comments and before // meta tag robots):

Code: [Select]
if (osc_is_publish_page()) {
$limit = 2;
if (osc_user_field('i_items') >= $limit) {
    osc_add_flash_error_message(sprintf(_m("You can't post more than %d listings"), $limit));
    header("Location: " . osc_base_url());
    exit;
}
}

Change the value of $limit variable if you want to allow more (or less, only one ad per user).

Regards
« Last Edit: February 09, 2018, 01:26:48 pm by teseo »

BritWeb

  • Hero Member
  • *****
  • Posts: 770
  • If it ain't broke, don't fix it.
Re: Limiting number of postings per user
« Reply #2 on: October 23, 2016, 12:34:00 pm »
Many thanks, teseo

Just to take it a step further, how can we set limit to number of listings separately for companies and individuals.?

Thank you once again.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Limiting number of postings per user
« Reply #3 on: October 23, 2016, 01:44:19 pm »
***CORRECTED***

Hi,

Code: [Select]
if (osc_is_publish_page()) {
    $limits = array(2, 10); // (Individual, Company)
    $current_limit = $limits[osc_user_field("b_company")];

    if (osc_user_field('i_items') >= $current_limit) {
        osc_add_flash_error_message(sprintf(_m("You can't post more than %d listings"), $current_limit));
        header("Location: " . osc_base_url());
        exit;
    }
}

Regards
« Last Edit: February 09, 2018, 01:27:33 pm by teseo »

BritWeb

  • Hero Member
  • *****
  • Posts: 770
  • If it ain't broke, don't fix it.
Re: Limiting number of postings per user
« Reply #4 on: October 23, 2016, 02:20:33 pm »
Great! Thank you, teseo

Much appreciated! Kind regards

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Limiting number of postings per user
« Reply #5 on: October 23, 2016, 02:30:03 pm »
You're welcome :) Please add [SOLVED] to the title of this thread.

Regards

MagicM

  • Newbie
  • *
  • Posts: 17
Re: Limiting number of postings per user (solved)
« Reply #6 on: May 17, 2019, 12:32:08 pm »
Instead of Individual/Company is possible to allow different number of ads for normal users and PREMIUM?