Attempting to upgrade theme having built news site using Co-Authors Plus

Posted in: Newsmag
Post count: 5

The site has been working utilizing the Guest Authors feature of Co-Authors Plus. This required some custom code to get working. As we are required (security and PHP version) to update from NewsMag 3x to NewsMag 5x (repurchased the theme). This feature stack is no longer working. The guest author is selected in editor, but is not making it’s way to the front end.
I found this reply by Calin on this post https://forum.tagdiv.com/topic/regarding-adding-multiple-authors-on-newspaper-theme/, regarding the Newspaper theme. However, it does not work with NewsMag (the multiple includes/ “/parts/single” was in the theme root for Newsmag but no longer exists. If you could modify this post with corresponding code for the loop-single.php file, that would be very helpful.

Post count: 35449

Hi,
The root path for Newsmag is wp-content/plugins/td-composer/legacy/Newsmag/parts/single and edit the file that represents the post style you are using. If you are using the default post style – wp-content/plugins/td-composer/legacy/Newsmag/loop-single.php
Also, those changes can be set in a child theme that will have the same structure.
I hope this will help you!

Post count: 5

Thank you very much. Does everything else in that post apply since that was written for the newspaper theme?

Post count: 35449

Hello,
Mostly yes, since that is related to the standard templates from Newspaper that are similar with those from Newsmag.
Thank you!

Post count: 5

Hmm, I have made the prescribed modifications.

I added the code to the child functions.php file. This didn’t break things, but I can’t see that it affects anything. After adding the code to the loop-single.php and parts/single/loop-single-2.php which is the primary template we use, the post that has a guest author in the backend editor, is still displaying the #1 is still being substituted.

As co-authors/guest authors are a critical function in our site, and as the site is almost a decade of weekly news stories, changing is untenable. Without this theme update we cannot update php. Obvious problems there, including getting shut down by our hosting platform.

Can you please update your very helpful post of Jan 24, 2023 to encompass the NewsMag theme? Or what other options might we have?

Post count: 35449

Hi,
Make sure that you all both the loop-single-x.php and single_template_x.php
Also, now there are most of users that use this guide for co authors – Adding Multiple Authors to Your Articles
Thank you!

Post count: 5

Hello Calin,
I appreciate your assistance. Unfortunately the last article you posted assumes that it works as it should, but it does not. The proper authors are appearing in the post editor, but this is not displaying on the home, archive page or the post page.

So, according to your input, I have added the code prescribed on the post exactly. (Following https://forum.tagdiv.com/topic/regarding-adding-multiple-authors-on-newspaper-theme/). Pasted code into child theme function.php. Added code to loop-single-2.php and single_template_2.php which is the primary template.

Again, this did not impact the homepage, listing page, or the post page:
See staging site:
https://nondoc1dev.wpenginepowered.com/category/sports/
This page has posts attributed to guest author Jeremy Cowen in the editor:
https://nondoc1dev.wpenginepowered.com/2023/12/23/big-man-on-campus-ryan-minor-made-memories-at-ou/
This shows all posts attributed:
https://nondoc1dev.wpenginepowered.com/author/jeremy-cowen-contributor-in-chief/

I have cleared caches. Do I have any recourse?

Thank you

Post count: 20688

Hi,

I am testing this as well.

The guide mentioned here https://forum.tagdiv.com/topic/regarding-adding-multiple-authors-on-newspaper-theme/ is for the post pages, not the modules that blocks use, or any other locations on the website.

So first I added the code in the child theme functions file https://prnt.sc/hTPNzhlfY7X0

I copied the files for post template 2, which I see you are using.
So these files from the composer https://prnt.sc/sYUozCJiLp19
Into the child theme via this path Newsmag-child/parts/single https://prnt.sc/uG_2Uqw4Fcae

I replaced the code in the single file https://prnt.sc/ICqKDs-XYUX6
And in the loop file https://prnt.sc/EJMd1roozXhb

I entered the CSS in the theme panel https://prnt.sc/7dwNgqXIkJKe

I installed the co authors plus plugin and set 2 authors https://prnt.sc/XduTPL7-Dycg

The result https://prnt.sc/iNwHwugnwHLB and https://prnt.sc/_CBidAgkxti6

It seems to work fine. If it doesn’t for you, maybe its not done correctly. Could you please doublecheck? Or if you want, we can take a look as well. You can send us an email at contact@tagdiv.com and provide access to the staging website. Let us know.

Regards, Simion C.

Post count: 162

Hello @Calin and @Simion

I have a similar issue, but I used ACF to create a Co-Author field and am able to display it on the post as well. The post however, does not show up in the second author’s archive page or in the modules for blocks elsewhere (obviously). I am using the Newspaper theme (not Newsmag).

Can you confirm that I need to follow similar steps to achieve the same result? Or is there another way you would suggest considering am using ACF?

Thank you in advance!

Post count: 35449

Hello theheritagelab,
Yes, you can use ACF to create a Co-Author field, we’ll be something like this:
Add a new field:

  • Field Type: Relationship (this allows you to link other users/authors).
  • Label: Co-Authors.
  • Name: co_authors.
  • Post Object: Set the relationship to link users (authors) as co-authors.
  • Under Field Settings, choose:

  • Post Type: Select “Users” (or “Authors” if using a specific role for authors).
  • Filter by Taxonomy or Role: You can filter to only show users with the role of “Author” if desired.
  • Then you need to use a single post template, edit it using tagDiv Composer and add the custom filed element and select the acf for authors- https://i.imgur.com/3pgDu6E.pnghttps://i.imgur.com/LCkuu1D.jpeghttps://i.imgur.com/vhOMOJI.png

    To display the co-authors on blocks you need to create modules were you can create the layout of blocks and add elements you want there you can add the custom fields too – https://forum.tagdiv.com/modules-builder-newspaper-theme/https://forum.tagdiv.com/flex-block-builder-flex-loop-builder/

    Thank you!

    Post count: 162

    Hey @Calin,

    Thanks, though I think am still a bit unclear or perhaps I did not explain correctly.

    I used ACF to create a Co-Author field. My Co-Author field group is a user-type currently and in the backend, I can choose the user from a dropdown list. I am able to display it on the post as well by modifying the single-post template.
    Then you need to use a single post template, edit it using tagDiv Composer and add the custom filed element and select the acf for authors- https://i.imgur.com/3pgDu6E.pnghttps://i.imgur.com/LCkuu1D.jpeghttps://i.imgur.com/vhOMOJI.png
    — so I guess this part is sorted.

    What am unable to do is, have the post show up in the author archive of the Co Author. It only shows in the primary author’s archive.

    To display the co-authors on blocks you need to create modules were you can create the layout of blocks and add elements you want there you can add the custom fields too – https://forum.tagdiv.com/modules-builder-newspaper-theme/https://forum.tagdiv.com/flex-block-builder-flex-loop-builder/ — Thank you, I will try this!

    Post count: 35449

    Hi theheritagelab, let me know if I correctly understand, if are referring that and articles that has 2 authors should be display for both authors when you access the https://www.domain.com/author/author1/ and https://www.domain.com/author/author2/, right?
    For this you’ll need to modify the query for the author archive pages so that it checks both the main author and the co-authors field set by ACF.
    add_action('pre_get_posts', 'custom_author_query');
    function custom_author_query($query) {
    if ($query->is_author() && $query->is_main_query()) {
    $author_id = get_queried_object_id();
    // Modify this with your actual ACF field key for co-authors
    $meta_query = array(
    array(
    'key' => 'acf_co_authors_field', // Replace this with your ACF co-authors field name
    'value' => '"' . $author_id . '"',
    'compare' => 'LIKE'
    )
    );
    $query->set('meta_query', $meta_query);
    }
    }

    The above code needs to be set in a child theme in functions.php also the above cone it is possible to be need to be adjusted.
    Thank you!

    Post count: 162

    Hey @Calin,

    I tried this as well, but with no success. It returns “no posts to display” for both authors!

    In one article, I have 2 authors — 1 author set via WP’s usual “author” and 2 Author from the ACF User field (co_author).

    On the front end, of course, it is possible to display both authors — but when I click on Author 1 (https://www.domain.com/author/author1/ ), I am able to see the article. But not for Author 2.

    After adding the code below, the front end display for Author 1 shows “No Posts to Display”. What am I missing? Should both authors be chosen via ACF?

    add_action(‘pre_get_posts’, ‘custom_author_query’);
    function custom_author_query($query) {
    if ($query->is_author() && $query->is_main_query()) {
    $author_id = get_queried_object_id();
    // Modify this with your actual ACF field key for co-authors
    $meta_query = array(
    array(
    ‘key’ => ‘co_author’,
    ‘value’ => ‘”‘ . $author_id . ‘”‘,
    ‘compare’ => ‘LIKE’
    )
    );
    $query->set(‘meta_query’, $meta_query);
    }
    }

    Post count: 35449

    Hi theheritagelab, the code that I provided is as a suggestion after some examples I saw on google, so to integrate the code on your website you’ll need a developer or someone that can handle the php functions from WordPress. I do my best, but this is over our skills on support.
    I funded a better code, maybe this will work better.
    add_action('pre_get_posts', 'custom_author_query');
    function custom_author_query($query) {
    // Only modify the main query for author archive pages
    if ($query->is_author() && $query->is_main_query()) {
    $author_id = get_queried_object_id();

    // Get the default query for posts by the main author
    $meta_query = array(
    'relation' => 'OR', // Combine conditions with OR
    array(
    'key' => 'co_author', // For co-author meta field
    'value' => '"' . $author_id . '"',
    'compare' => 'LIKE'
    ),
    array(
    'relation' => 'AND', // Default query for main author
    array(
    'key' => '_edit_last', // Ensuring not filtered out by other conditions
    'compare' => 'EXISTS'
    ),
    )
    );

    $query->set('meta_query', $meta_query);
    $query->set('author', $author_id); // Include posts where the main author is the current author
    }
    }

    Post count: 162

    Hi @Calin, unfortunately none of these solutions worked; if we figure something out, we’ll share for sure.

    Viewing 15 posts - 1 through 15 (of 15 total)
    The forum ‘Newsmag’ is closed to new topics and replies.