so this is my setup, I have Jobs Custom Post Type, with 20 Categories, and I already created 20 Lists and added them to Subscribe link of each job form, so if someone fill mailpoet form on Job of IT category so Mailpoet will add them to IT List, now what I did I created custom shortcode using funcitons.php file,
I want to send latest 6 jobs from category to same list if new job is posted on that category, (how can I get the last sent date of mailpoet in that category so I can only send limited new jobs in case there is only 2 or 3 new jobs in that category, I haven’t explore that part, may be your developer can shed light on this part and give me some hooks etc).
Anyways this is how I am creating custom shortcode which I then add into Mailpoet email body as [custom:latest_posts "my-job-category"]
and it shows latest 6 jobs from my-job- category,when emails are sent.
function mailpoet_custom_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body, $arguments) {
preg_match('/[custom:latest_posts\s+("[^"]+")?]/', $shortcode, $matches);
$category_slug = '';
if (!empty($matches[1])) {
$category_slug = trim($matches[1], '"');
}
$args = array(
'posts_per_page' => 6,
'post_type' => 'job_listing',
'post_status' => 'publish',
'tax_query' => array(
array (
'taxonomy' => 'job_listing_category',
'field' => 'slug',
'terms' => $category_slug,
)
),
'orderby' => 'date',
'order' => 'DESC',
);
$latest_posts = new WP_Query($args);
Now problem is that I am querying and showing these jobs in my own template, so I don’t need Latest Post widget to show posts in email body, but somehow only trigger this when there is new jobs in that category.
Okay I didn’t find solution but I did trick, I added the Latest Post Widget, and change Post to 1, then changed link color to white which is my background color, and changed all other links on pages to different colors manually, now when some new jobs are posted in category it does trigger email.
but is there a neat way to do this ?
also can you tell me if there is a way to add some check in WP_Query to only send jobs which are posted after last mailpoet email ?