jueves, 25 de septiembre de 2014

Publicar en WordPress desde Microsoft Access via XMLRPC Parte 8

Continuando con los artículos en donde estamos investigando cómo conectar Microsoft Access con WordPress vía XML-RPC, en esta entrega veremos un caso sencillo, pero que puede ser útil: ¿Cómo borrar un post en WordPress? Antes de continuar recomiendo que lean los artículos anteriores:


Para cumplir con lo requerido, trabajaremos con wp.deletePost. Hay que tener en cuenta que el método también sirve para eliminar archivos de la librería de medios.




El código

Function BorrarPostEnWordPress(PostId As String) As String
 
    ' Datos de Autenticación
    CargarConstantes
    txtURL = SITIO
    txtUserName = USUARIO
    txtPassword = PASSWORD
    
    ' Datos del Post
    txtId = PostId
      
    ' ServerXMLHTTP
    Dim objSvrHTTP As ServerXMLHTTP
    Dim strT As String
    Set objSvrHTTP = New ServerXMLHTTP
  
    ' Autenticación
    objSvrHTTP.Open "POST", txtURL, False, CStr(txtUsuario), CStr(txtPassword)
    objSvrHTTP.setRequestHeader "Accept", "application/xml"
    objSvrHTTP.setRequestHeader "Content-Type", "application/xml"

    strT = strT & "<methodCall>"
    
    ' Acción
    strT = strT & "<methodName>wp.deletePost</methodName>"
    
    ' General
    strT = strT & "<params>"
    strT = strT & "<param><value><string>0</string></value></param>"
    strT = strT & "<param><value>" & txtUserName & "</value></param>"
    strT = strT & "<param><value><string>" & txtPassword & "</string></value></param>"
    strT = strT & "<param><value><int>" & txtId & "</int></value></param>"
    strT = strT & "<param>"
    strT = strT & "</param>"
    strT = strT & "</params>"
    strT = strT & "</methodCall>"
    
    ' Publicación
    objSvrHTTP.send strT
    
    ' Debug
    Debug.Print objSvrHTTP.responseText
    'MsgBox objSvrHTTP.responseText
    BorrarPostEnWordPress = resultado(objSvrHTTP.responseText, "EDIT")

End Function


Bibliografía



Hasta la próxima!

0 comentarios:

Publicar un comentario