Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post to a Specific Category? #86

Open
GlennIM opened this issue Jul 7, 2018 · 3 comments
Open

Post to a Specific Category? #86

GlennIM opened this issue Jul 7, 2018 · 3 comments

Comments

@GlennIM
Copy link

GlennIM commented Jul 7, 2018

How can I make a blog post to a specific category?

Does any one have a code example I can use?

Thanks - Glenn

@GlennIM
Copy link
Author

GlennIM commented Jul 7, 2018

I have a working example that was in one of the other posts here. But I need to know how I can get a list of category names/IDs from the client so I can post to the category of my choosing. Can I get a code snippet on doing that, please?

Thanks

@Blackcat156
Copy link

Get the category ID:
tim 20180727114427
click “Edit” ,look at the url

http://localhost/wordpress/wp-admin/term.php?taxonomy=category&tag_ID=1&post_type=post&wp_http_referer=%2Fwordpress%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory

Category is "tag_ID=" Back number,such as :1

   /// <summary>
    /// 发布到指定分类
    /// </summary>
    /// <param name="post"></param>
    /// <param name="category"></param>
    /// <param name="localUserInfo"></param>
    /// <returns></returns>
    internal static string PublishConent(Post post, List<int> category, Wphelper.UserInfo localUserInfo)
    {
        List<Term> TremsTemp = new List<Term>();
        WordPressClient wordPressClient = Wphelper.InitClient(localUserInfo);
        foreach (int count in category)
        {
            try
            {
              
                TremsTemp.Add(wordPressClient.GetTerm("category", count));//如果错误出现在这里就代表分类id写错了
            }
            catch (Exception ex)
            {
                PrintLog.Log(ex);
            }
        }
        post.Terms = TremsTemp.ToArray();
        return PublishConent(post, wordPressClient);
    }

@Blackcat156
Copy link

public struct UserInfo
{
private string userName;
private string password;
private string indexurl;

        public string UserName { get => userName; set => userName = value; }
        public string Password { get => password; set => password = value; }
        public string Indexurl { get => indexurl; set => indexurl = value; }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants